本文整理汇总了Java中com.google.gson.GsonBuilder.excludeFieldsWithoutExposeAnnotation方法的典型用法代码示例。如果您正苦于以下问题:Java GsonBuilder.excludeFieldsWithoutExposeAnnotation方法的具体用法?Java GsonBuilder.excludeFieldsWithoutExposeAnnotation怎么用?Java GsonBuilder.excludeFieldsWithoutExposeAnnotation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.gson.GsonBuilder
的用法示例。
在下文中一共展示了GsonBuilder.excludeFieldsWithoutExposeAnnotation方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deserialize
import com.google.gson.GsonBuilder; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void deserialize(String jsonString) {
Type listType = new TypeToken<ArrayList<Logo>>() {
}.getType();
final GsonBuilder builder = new GsonBuilder();
builder.excludeFieldsWithoutExposeAnnotation();
final Gson gson = builder.create();
List<Logo> list = gson.fromJson(jsonString, listType);
for (int i = 0; i < list.size(); i++) {
list.get(i).setNid(i + 1);
}
this.addAll(list);
}
示例2: listKeyMaps
import com.google.gson.GsonBuilder; //导入方法依赖的package包/类
/**
* 将json转化为List<Map<String, Object>>
* @param jsonString
* @return
*/
public static List<Map<String, Object>> listKeyMaps(String jsonString) {
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
try {
GsonBuilder builder = new GsonBuilder();
// 不转换没有 @Expose 注解的字段
builder.excludeFieldsWithoutExposeAnnotation();
Gson gson = builder.create();
list = gson.fromJson(jsonString,
new TypeToken<List<Map<String, Object>>>() {
}.getType());
} catch (Exception e) {
e.printStackTrace();
}
return list;
}
示例3: deserialize
import com.google.gson.GsonBuilder; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void deserialize(String jsonString) {
Type listType = new TypeToken<ArrayList<Article>>() {
}.getType();
final GsonBuilder builder = new GsonBuilder();
builder.excludeFieldsWithoutExposeAnnotation();
final Gson gson = builder.create();
List<Article> list = gson.fromJson(jsonString, listType);
this.addAll(list);
}
示例4: deserialize
import com.google.gson.GsonBuilder; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void deserialize(String jsonString) {
final GsonBuilder builder = new GsonBuilder();
builder.excludeFieldsWithoutExposeAnnotation();
final Gson gson = builder.create();
Article w = gson.fromJson(jsonString, Article.class);
this.nid = w.nid;
this.title = w.title;
this.text = w.text;
this.author = w.author;
this.note = w.note;
}
示例5: serialize
import com.google.gson.GsonBuilder; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public String serialize() {
final GsonBuilder builder = new GsonBuilder();
builder.excludeFieldsWithoutExposeAnnotation();
builder.disableHtmlEscaping();
final Gson gson = builder.create();
return gson.toJson(this);
}
示例6: deserialize
import com.google.gson.GsonBuilder; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void deserialize(String jsonString) {
final GsonBuilder builder = new GsonBuilder();
builder.excludeFieldsWithoutExposeAnnotation();
final Gson gson = builder.create();
Logo w = gson.fromJson(jsonString, Logo.class);
this.nid = w.nid;
this.brand = w.brand;
}
示例7: getHomebrewGson
import com.google.gson.GsonBuilder; //导入方法依赖的package包/类
/**
* Returns a GSON instance with our converters applied.
*
* @return a GSON instance with our converters applied
*/
private static Gson getHomebrewGson() {
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.excludeFieldsWithoutExposeAnnotation();
gsonBuilder.registerTypeHierarchyAdapter(LocalDateTime.class, new LocalDateTimeSerializer());
return gsonBuilder.create();
}
示例8: json2Object
import com.google.gson.GsonBuilder; //导入方法依赖的package包/类
/**
* 将json转化为cls对象
* @param jsonString json字符串
* @param cls 对应的类
* @return
*/
public static <T> T json2Object(String jsonString, Class<T> cls) {
T t = null;
try {
GsonBuilder builder = new GsonBuilder();
// 不转换没有 @Expose 注解的字段
builder.excludeFieldsWithoutExposeAnnotation();
Gson gson = builder.create();
t = gson.fromJson(jsonString, cls);
} catch (Exception e) {
e.printStackTrace();
}
return t;
}
示例9: deserialize
import com.google.gson.GsonBuilder; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void deserialize(String jsonString) {
Type listType = new TypeToken<ArrayList<Customer>>() {
}.getType();
final GsonBuilder builder = new GsonBuilder();
builder.excludeFieldsWithoutExposeAnnotation();
final Gson gson = builder.create();
List<Customer> list = gson.fromJson(jsonString, listType);
this.addAll(list);
}
示例10: deserialize
import com.google.gson.GsonBuilder; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void deserialize(String jsonString) {
final GsonBuilder builder = new GsonBuilder();
builder.excludeFieldsWithoutExposeAnnotation();
final Gson gson = builder.create();
Customer w = gson.fromJson(jsonString, Customer.class);
this.wid = w.wid;
this.lastNameCustomer = w.lastNameCustomer;
this.firstNameCustomer = w.firstNameCustomer;
}
示例11: getGson
import com.google.gson.GsonBuilder; //导入方法依赖的package包/类
@Provides
@Nonnull
public Gson getGson(@Nonnull Injector injector) {
GsonBuilder builder = new GsonBuilder();
addTypeAdapters(builder, injector);
builder.setPrettyPrinting();
builder.excludeFieldsWithoutExposeAnnotation();
return builder.create();
}
示例12: FileManager
import com.google.gson.GsonBuilder; //导入方法依赖的package包/类
private FileManager() {
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.excludeFieldsWithoutExposeAnnotation();
gson = gsonBuilder.create();
}