本文整理匯總了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();
}