List of usage examples for com.google.gson GsonBuilder excludeFieldsWithoutExposeAnnotation
public GsonBuilder excludeFieldsWithoutExposeAnnotation()
From source file:org.ndogen.util.FileUtils.java
License:Open Source License
public static String objectToJson(Object o) { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.excludeFieldsWithoutExposeAnnotation(); gsonBuilder.setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); Gson gson = gsonBuilder.create();//from w ww . j av a 2 s.co m String json = gson.toJson(o); return json; }
From source file:org.openmrs.mobile.api.RestServiceBuilder.java
License:Mozilla Public License
private static GsonConverterFactory buildGsonConverter() { GsonBuilder gsonBuilder = new GsonBuilder(); Gson myGson = gsonBuilder.excludeFieldsWithoutExposeAnnotation() .registerTypeHierarchyAdapter(Resource.class, new ResourceSerializer()) .registerTypeHierarchyAdapter(Observation.class, new ObservationDeserializer()).create(); return GsonConverterFactory.create(myGson); }
From source file:org.openmrs.mobile.utilities.FormService.java
License:Mozilla Public License
public static Form getForm(String valueReference) { String unescapedValueReference = StringUtils.unescapeJavaString(valueReference); GsonBuilder builder = new GsonBuilder(); builder.excludeFieldsWithModifiers(Modifier.FINAL, Modifier.TRANSIENT, Modifier.STATIC); builder.excludeFieldsWithoutExposeAnnotation(); Gson gson = builder.create();/* w w w . j av a 2 s. com*/ return gson.fromJson(unescapedValueReference, Form.class); }
From source file:org.openmrs.mobile.utilities.ResourceSerializer.java
License:Open Source License
@NonNull private Gson getGson() { GsonBuilder gsonBuilder = new GsonBuilder(); return gsonBuilder.excludeFieldsWithoutExposeAnnotation().create(); }
From source file:org.openmrs.mobile.utilities.ResourceSerializer.java
License:Open Source License
@NonNull private Gson getObsGson() { GsonBuilder gsonBuilder = new GsonBuilder(); return gsonBuilder.excludeFieldsWithoutExposeAnnotation() .setExclusionStrategies(new ObservationExclusionStrategy()).create(); }
From source file:org.openqa.grid.common.RegistrationRequest.java
License:Apache License
public JsonObject toJson() { GsonBuilder builder = new GsonBuilder(); builder.registerTypeAdapter(new TypeToken<List<DesiredCapabilities>>() { }.getType(), new CollectionOfDesiredCapabilitiesSerializer()); return builder.excludeFieldsWithoutExposeAnnotation().create().toJsonTree(this, RegistrationRequest.class) .getAsJsonObject();/*from www . j ava 2s . c o m*/ }
From source file:org.openqa.grid.common.RegistrationRequest.java
License:Apache License
/** * Create an object from a registration request formatted as a JsonObject * * @param json JsonObject/*from ww w. j a v a 2s. c o m*/ * @return */ public static RegistrationRequest fromJson(JsonObject json) throws JsonSyntaxException { GsonBuilder builder = new GsonBuilder(); builder.registerTypeAdapter(new TypeToken<List<DesiredCapabilities>>() { }.getType(), new CollectionOfDesiredCapabilitiesDeSerializer()); RegistrationRequest request = builder.excludeFieldsWithoutExposeAnnotation().create().fromJson(json, RegistrationRequest.class); return request; }
From source file:org.openqa.grid.common.RegistrationRequest.java
License:Apache License
/** * Create an object from a registration request formatted as a json string. * * @param json JSON String/* w w w . ja v a 2 s . c o m*/ * @return */ public static RegistrationRequest fromJson(String json) throws JsonSyntaxException { GsonBuilder builder = new GsonBuilder(); builder.registerTypeAdapter(new TypeToken<List<DesiredCapabilities>>() { }.getType(), new CollectionOfDesiredCapabilitiesDeSerializer()); RegistrationRequest request = builder.excludeFieldsWithoutExposeAnnotation().create().fromJson(json, RegistrationRequest.class); return request; }
From source file:org.openqa.grid.internal.utils.configuration.GridHubConfiguration.java
License:Apache License
/** * @param json JsonObject to load configuration from */// w w w . ja va 2 s. com public static GridHubConfiguration loadFromJSON(JsonObject json) { try { GsonBuilder builder = new GsonBuilder(); GridHubConfiguration.staticAddJsonTypeAdapter(builder); return builder.excludeFieldsWithoutExposeAnnotation().create().fromJson(json, GridHubConfiguration.class); } catch (Throwable e) { throw new GridConfigurationException("Error with the JSON of the config : " + e.getMessage(), e); } }
From source file:org.openqa.grid.internal.utils.configuration.GridNodeConfiguration.java
License:Apache License
/** * @param json JsonObject to load configuration from *///from w ww . j a v a2s .co m public static GridNodeConfiguration loadFromJSON(JsonObject json) { try { GsonBuilder builder = new GsonBuilder(); GridNodeConfiguration.staticAddJsonTypeAdapter(builder); GridNodeConfiguration config = builder.excludeFieldsWithoutExposeAnnotation().create().fromJson(json, GridNodeConfiguration.class); if (config.configuration != null) { // caught below throw new GridConfigurationException("Deprecated -nodeConfig file encountered. Please update" + " the file to work with Selenium 3. See https://github.com" + "/SeleniumHQ/selenium/wiki/Grid2#configuring-the-nodes-by-json" + " for more details."); } return config; } catch (Throwable e) { throw new GridConfigurationException("Error with the JSON of the config : " + e.getMessage(), e); } }