使用GSON不解析字段,只保留json原始字符串 [英] Using GSON do not parse a field, only keep it with the json raw string

查看:637
本文介绍了使用GSON不解析字段,只保留json原始字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java中使用GSON有任何注释,我可以指出一个字段,即使它是一个对象,它应该将它保留为原始字符串。 ?

Using GSON in Java is there any annotation where I can indicate a field that it should keep it as a raw string even though it is an object. ?

或者什么是最简单的方法来实现这一目标?

Or What would be the easiest way to achieve this?

//This is the original
    @SerializedName("perro")
    public Perro perro

//This is what I want to achieve 
    @SerializedName("perro")
    public String perro

So the result should be 
perro = "{"Users":[{"Name":"firulais","Raza":"beagle"},{"Name":"Spike","Value":"Terrier"}]}"


推荐答案

我发现这工作的唯一方法是使用

The only way I found this to work was using

public JsonElement perro;

这篇关于使用GSON不解析字段,只保留json原始字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆