List of usage examples for com.google.gson GsonBuilder serializeNulls
boolean serializeNulls
To view the source code for com.google.gson GsonBuilder serializeNulls.
Click Source Link
From source file:org.eclipse.packagedrone.repo.channel.impl.ChannelServiceModelProvider.java
License:Open Source License
protected Gson createGson() { final GsonBuilder builder = new GsonBuilder(); builder.setPrettyPrinting();//from ww w . j av a 2 s .co m builder.serializeNulls(); builder.setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); builder.registerTypeAdapter(DeployGroup.class, new DeployGroupTypeAdapter()); builder.registerTypeAdapter(MetaKey.class, MetaKeyTypeAdapter.INSTANCE); return builder.create(); }
From source file:org.foxbpm.web.common.util.JSONUtil.java
License:Apache License
private static String toJson(Object target, Type targetType, boolean isSerializeNulls, Double version, String datePattern, boolean excludesFieldsWithoutExpose) { if (target == null) return EMPTY_JSON; GsonBuilder builder = new GsonBuilder(); if (isSerializeNulls) builder.serializeNulls(); if (version != null) builder.setVersion(version.doubleValue()); // if (StringUtil.isEmpty(datePattern)) // datePattern = DEFAULT_DATE_PATTERN; builder.setDateFormat(datePattern);//from ww w. j a va 2 s.c om if (excludesFieldsWithoutExpose) builder.excludeFieldsWithoutExposeAnnotation(); String result = null; Gson gson = builder.create(); try { if (targetType != null) { result = gson.toJson(target, targetType); } else { result = gson.toJson(target); } } catch (Exception ex) { if (target instanceof Collection || target instanceof Iterator || target instanceof Enumeration || target.getClass().isArray()) { result = EMPTY_JSON_ARRAY; } else result = EMPTY_JSON; } return result; }
From source file:org.lastaflute.core.json.SimpleJsonManager.java
License:Apache License
protected void setupSerializeNullsSettings(GsonBuilder builder, boolean serializeNulls) { if (serializeNulls) { builder.serializeNulls(); }/* ww w. j a va2 s. com*/ }
From source file:org.mobicents.servlet.restcomm.http.IncomingPhoneNumbersEndpoint.java
License:Open Source License
@PostConstruct public void init() throws ObjectInstantiationException { final DaoManager storage = (DaoManager) context.getAttribute(DaoManager.class.getName()); configuration = (Configuration) context.getAttribute(Configuration.class.getName()); super.init(configuration.subset("runtime-settings")); dao = storage.getIncomingPhoneNumbersDao(); accountsDao = storage.getAccountsDao(); phoneNumberProvisioningManager = (PhoneNumberProvisioningManager) context .getAttribute("PhoneNumberProvisioningManager"); if (phoneNumberProvisioningManager == null) { final String phoneNumberProvisioningManagerClass = configuration .getString("phone-number-provisioning[@class]"); Configuration phoneNumberProvisioningConfiguration = configuration.subset("phone-number-provisioning"); Configuration telestaxProxyConfiguration = configuration.subset("runtime-settings") .subset("telestax-proxy"); phoneNumberProvisioningManager = (PhoneNumberProvisioningManager) new ObjectFactory( getClass().getClassLoader()).getObjectInstance(phoneNumberProvisioningManagerClass); ContainerConfiguration containerConfiguration = new ContainerConfiguration(getOutboundInterfaces()); phoneNumberProvisioningManager.init(phoneNumberProvisioningConfiguration, telestaxProxyConfiguration, containerConfiguration); context.setAttribute("phoneNumberProvisioningManager", phoneNumberProvisioningManager); }//from ww w. ja va 2s .c o m Configuration callbackUrlsConfiguration = configuration.subset("phone-number-provisioning") .subset("callback-urls"); phoneNumberParameters = new PhoneNumberParameters(callbackUrlsConfiguration.getString("voice[@url]"), callbackUrlsConfiguration.getString("voice[@method]"), false, callbackUrlsConfiguration.getString("sms[@url]"), callbackUrlsConfiguration.getString("sms[@method]"), callbackUrlsConfiguration.getString("fax[@url]"), callbackUrlsConfiguration.getString("fax[@method]"), callbackUrlsConfiguration.getString("ussd[@url]"), callbackUrlsConfiguration.getString("ussd[@method]")); final IncomingPhoneNumberConverter converter = new IncomingPhoneNumberConverter(configuration); final GsonBuilder builder = new GsonBuilder(); builder.serializeNulls(); builder.registerTypeAdapter(IncomingPhoneNumber.class, converter); builder.setPrettyPrinting(); gson = builder.create(); xstream = new XStream(); xstream.alias("RestcommResponse", RestCommResponse.class); xstream.registerConverter(converter); xstream.registerConverter(new IncomingPhoneNumberListConverter(configuration)); xstream.registerConverter(new AvailableCountriesConverter(configuration)); xstream.registerConverter(new RestCommResponseConverter(configuration)); }
From source file:org.nimbustools.ctxbroker.rest.BrokerResource.java
License:Apache License
public BrokerResource() { try {// w w w .j av a2 s. co m this.home = discoverHome(); } catch (Exception e) { throw new RuntimeException(e); } GsonBuilder gsonBuilder = new GsonBuilder(); gson = gsonBuilder.serializeNulls().create(); }
From source file:org.objectpocket.ObjectPocketImpl.java
License:Apache License
private Gson configureGson() { if (gson == null) { GsonBuilder gsonBuilder = new GsonBuilder(); // null serialization if (serializeNulls) { gsonBuilder.serializeNulls(); }//from w ww. java 2 s. co m // This is where the referencing entry magic happens gsonBuilder.registerTypeAdapterFactory(new CustomTypeAdapterFactory(this)); // add custom type adapters for (Type type : typeAdapterMap.keySet()) { for (Object typeAdapter : typeAdapterMap.get(type)) { gsonBuilder.registerTypeAdapter(type, typeAdapter); } } // pretty printing if (prettyPrinting) { gsonBuilder.setPrettyPrinting(); } gson = gsonBuilder.create(); } return gson; }
From source file:org.opendolphin.core.comm.JsonCodec.java
License:Apache License
public JsonCodec() { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.registerTypeAdapter(Date.class, new JsonSerializer<Date>() { @Override/*from w ww.j av a 2s .c o m*/ public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext context) { JsonObject element = new JsonObject(); element.addProperty(Date.class.toString(), new SimpleDateFormat(ISO8601_FORMAT).format(src)); return element; } }); gsonBuilder.registerTypeAdapter(Float.class, new JsonSerializer<Float>() { @Override public JsonElement serialize(Float src, Type typeOfSrc, JsonSerializationContext context) { JsonObject element = new JsonObject(); element.addProperty(Float.class.toString(), Float.toString(src)); return element; } }); gsonBuilder.registerTypeAdapter(Double.class, new JsonSerializer<Double>() { @Override public JsonElement serialize(Double src, Type typeOfSrc, JsonSerializationContext context) { JsonObject element = new JsonObject(); element.addProperty(Double.class.toString(), Double.toString(src)); return element; } }); gsonBuilder.registerTypeAdapter(BigDecimal.class, new JsonSerializer<BigDecimal>() { @Override public JsonElement serialize(BigDecimal src, Type typeOfSrc, JsonSerializationContext context) { JsonObject element = new JsonObject(); element.addProperty(BigDecimal.class.toString(), src.toString()); return element; } }); GSON = gsonBuilder.serializeNulls().create(); }
From source file:org.openlaszlo.remote.json.LZGsonMarshaller.java
License:Open Source License
@Override public byte[] createObject(Object object, String objectReturnType) { try {//from www .j a v a2 s . c o m GsonBuilder _gsonBuilder = getGsonBuilderInstance(); if (applyLzDefaultGsonProperties) { _gsonBuilder.setDateFormat("dd/MM/yyyy HH:mm:ss"); _gsonBuilder.serializeNulls(); _gsonBuilder.setPrettyPrinting(); } Gson gson = _gsonBuilder.create(); // String buf2 = new LZReturnObject(objectReturnType) // .createObjectProgram(object); // // mLogger.error("LZReturnObject1:"+buf); // mLogger.error("LZReturnObject2:"+buf2); String jsonOutput = gson.toJson(object); return jsonOutput.getBytes("UTF-8"); } catch (Exception err) { mLogger.error("[createObject]", err); } return null; }
From source file:org.openstreetmap.josm.plugins.openstreetcam.service.photo.OpenStreetCamService.java
License:LGPL
@Override public Gson createGson() { final GsonBuilder builder = new GsonBuilder(); builder.serializeNulls(); builder.registerTypeAdapter(Photo.class, new PhotoTypeAdapter()); builder.registerTypeAdapter(Segment.class, new SegmentTypeAdapter()); return builder.create(); }
From source file:org.openstreetmap.josm.plugins.openstreetcam.service.Service.java
License:Apache License
private GsonBuilder createGsonBuilder() { final GsonBuilder builder = new GsonBuilder(); builder.serializeNulls(); builder.registerTypeAdapter(Photo.class, new PhotoTypeAdapter()); return builder; }