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:com.ca.dvs.app.dvs_servlet.misc.VirtualServiceBuilder.java
License:Open Source License
/** * Deploy MAR to VSE and generate response to the newly VS URI * @param fileMar//from w ww . jav a 2s . co m * @param strVsName * @throws Exception */ private void deployVsMar(File fileMar, String strVsName) throws Exception { try { // Deploy MAR this.vseCtrlr.deployMar(fileMar); } catch (Exception e) { String msg = String.format("Failed to deploy a virtual service from MAR file - %s", e.getMessage()); throw new Exception(msg, e.getCause()); } try { // Validate newly deployed service // success - form response body containing URL to new service (LISA Host, base URL, port) // fail - form response body containing error message Thread.sleep(getVseServiceReadyWaitSeconds() * 1000); // wait to check status of the VS VirtualService vs = vseCtrlr.getVirtualService(strVsName); if (vs.getStatus() == 2) { // form actions URLs hash map Map<String, Object> mapActions = formActionURIs(vs.getServiceCtrlUri()); // form messages hash map Map<String, Object> mapMsg = new LinkedHashMap<String, Object>(); Map<String, Object> mapMsgWarn = new LinkedHashMap<String, Object>(); Map<String, Object> mapMsgErr = new LinkedHashMap<String, Object>(); Map<String, Object> mapSvcWarnCreateMar = this.marObject.getWarnings(); Map<String, Object> mapSvcErrCreateMar = this.marObject.getErrors(); if (mapSvcWarnCreateMar.size() > 0) mapMsgWarn.put("createMarFile", mapSvcWarnCreateMar); if (mapSvcErrCreateMar.size() > 0) mapMsgErr.put("createMarFile", mapSvcErrCreateMar); mapMsg.put("serviceWarnings", mapMsgWarn); mapMsg.put("serviceErrors", mapMsgErr); // put into map for response Map<String, Object> map = new LinkedHashMap<String, Object>(); map.put("serviceName", vs.getName()); map.put("serviceUrl", vs.getServiceUri().toString()); map.put("actions", mapActions); map.put("messages", mapMsg); GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.setPrettyPrinting(); gsonBuilder.serializeNulls(); Gson gson = gsonBuilder.create(); this.response = Response.status(Status.OK).entity(gson.toJson(map)).build(); } else { this.response = Response.status(Status.INTERNAL_SERVER_ERROR) .entity(String.format("Service name '%s' is deployed but failed to start", strVsName)) .build(); } } catch (Exception e) { String msg = String.format("Service name '%s' is deployed but failed to start - %s", strVsName, e.getMessage()); throw new Exception(msg, e.getCause()); } }
From source file:com.ca.dvs.app.dvs_servlet.resources.RAML.java
License:Open Source License
/** * Get the servlet configuration//from w w w. j a v a2 s . c o m * <p> * @return HTTP response containing the Servlet configuration in JSON format */ @GET @Path("config") @Produces(MediaType.APPLICATION_JSON) public Response getConfig() { log.info("GET raml/config"); Map<String, Object> configMap = new LinkedHashMap<String, Object>(); try { Context initialContext = new InitialContext(); Context envContext = (Context) initialContext.lookup("java:comp/env"); configMap.put("vseServerUrl", envContext.lookup("vseServerUrl")); configMap.put("vseServicePortRange", envContext.lookup("vseServicePortRange")); configMap.put("vseServiceReadyWaitSeconds", envContext.lookup("vseServiceReadyWaitSeconds")); } catch (NamingException e) { e.printStackTrace(); log.error("Failed to obtain servlet configuration", e.getCause()); } GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.setPrettyPrinting(); gsonBuilder.serializeNulls(); Gson gson = gsonBuilder.create(); Response response = Response.status(200).entity(gson.toJson(configMap)).build(); return response; }
From source file:com.ca.dvs.app.dvs_servlet.resources.ROOT.java
License:Open Source License
/** * @return HTTP response containing DVS servlet configuration parameters in JSON format *///from www . ja va 2s. c om @GET @Path("config") @Produces(MediaType.APPLICATION_JSON) public Response getConfig() { log.info("GET /config"); Map<String, Object> configMap = new LinkedHashMap<String, Object>(); try { Context initialContext = new InitialContext(); Context envContext = (Context) initialContext.lookup("java:comp/env"); configMap.put("vseServerUrl", envContext.lookup("vseServerUrl")); configMap.put("vseServicePortRange", envContext.lookup("vseServicePortRange")); configMap.put("vseServiceReadyWaitSeconds", envContext.lookup("vseServiceReadyWaitSeconds")); } catch (NamingException e) { e.printStackTrace(); } GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.setPrettyPrinting(); gsonBuilder.serializeNulls(); Gson gson = gsonBuilder.create(); Response response = Response.status(200).entity(gson.toJson(configMap)).build(); return response; }
From source file:com.ca.dvs.utilities.raml.JsonUtil.java
License:Open Source License
/** * Serialize a Java Map into a JSON string * <p>/*from w w w . j av a2s.c om*/ * @param objMap the source Java Map * @return the serialized Java Map in JSON format */ public static String serialize(Map<String, Object> objMap) { String json = null; if (null != objMap && objMap.size() > 0) { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.setPrettyPrinting(); gsonBuilder.serializeNulls(); Gson gson = gsonBuilder.create(); json = gson.toJson(objMap); } return json; }
From source file:com.ca.dvs.utilities.raml.JsonUtil.java
License:Open Source License
/** * Serialize a Java object into a JSON string * <p>/*from w w w . j ava 2s . c om*/ * @param obj the source Java object * @return the serialized Java object in JSON format */ public static String serialize(Object obj) { String json = null; if (null != obj) { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.setPrettyPrinting(); gsonBuilder.serializeNulls(); Gson gson = gsonBuilder.create(); json = gson.toJson(obj); } return json; }
From source file:com.ca.dvs.utilities.raml.RamlUtil.java
License:Open Source License
/** * @param raml the Raml object from which to extract schema information * @param resourceDir the directory anchor from which any possible included resources must be loaded from * @return the JSON schema object for all of the schemas in the Raml *///from w w w . j a v a 2s.co m public static String getSchemaJson(Raml raml, File resourceDir) { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.setPrettyPrinting(); gsonBuilder.serializeNulls(); Gson gson = gsonBuilder.create(); Map<String, Object> schemaMap = new LinkedHashMap<String, Object>(); List<Map<String, String>> schemas = raml.getSchemas(); for (Map<String, String> map : schemas) { for (Entry<String, String> entry : map.entrySet()) { schemaMap.put(entry.getKey(), entry.getValue()); } } return gson.toJson(schemaMap); }
From source file:com.ca.dvs.utilities.raml.RamlUtil.java
License:Open Source License
/** * @param raml the Raml object from which to extract Json sample data * @param resourceDir the directory anchor from which any possible included resources must be loaded from * @return the sample data for all resources in the raml, formatted as Json. *//*from w w w.j a v a2 s. c o m*/ public static String getSampleJson(Raml raml, File resourceDir) { Map<String, Map<String, Object>> sampleData = getSampleData(raml, resourceDir); GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.setPrettyPrinting(); gsonBuilder.serializeNulls(); Gson gson = gsonBuilder.create(); return gson.toJson(sampleData); }
From source file:com.cleanappsample.di.RootModule.java
License:Apache License
@Provides Gson provideGson() {/*from www .j av a2s. c o m*/ GsonBuilder builder = new GsonBuilder(); builder.registerTypeAdapterFactory(new AutoValueAdapterFactory()); builder.serializeNulls(); return builder.create(); }
From source file:com.cloudbees.eclipse.core.util.Utils.java
License:Open Source License
public static Gson createGson() { final GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.serializeSpecialFloatingPointValues(); gsonBuilder.serializeNulls(); // gsonBuilder.setPrettyPrinting(); // temporary // gsonBuilder.excludeFieldsWithoutExposeAnnotation(); Gson g = gsonBuilder.create();/*from w w w . j a va2 s . c o m*/ return g; }
From source file:com.dabay6.libraries.androidshared.util.GsonUtils.java
License:Open Source License
/** * Create a pre-configured {@link Gson} instance. * * @param serializeNulls determines if nulls will be serialized. * * @return {@link Gson} instance.// w w w . j a v a 2 s.c om */ private static Gson createGson(final boolean serializeNulls) { final GsonBuilder builder = new GsonBuilder(); if (serializeNulls) { builder.serializeNulls(); } return builder.create(); }