List of usage examples for com.google.gson GsonBuilder setPrettyPrinting
public GsonBuilder setPrettyPrinting()
From source file:org.openbaton.sdk.api.util.RestRequest.java
License:Apache License
/** * Create a request with a given url path *//* ww w .jav a 2s. co m*/ public RestRequest(String username, String password, String projectId, boolean sslEnabled, final String nfvoIp, String nfvoPort, String path, String version) { if (sslEnabled) { this.baseUrl = "https://" + nfvoIp + ":" + nfvoPort + "/api/v" + version + path; this.provider = "https://" + nfvoIp + ":" + nfvoPort + "/oauth/token"; } else { this.baseUrl = "http://" + nfvoIp + ":" + nfvoPort + "/api/v" + version + path; this.provider = "http://" + nfvoIp + ":" + nfvoPort + "/oauth/token"; } this.username = username; this.password = password; this.projectId = projectId; GsonBuilder builder = new GsonBuilder(); /*builder.registerTypeAdapter(Date.class, new JsonDeserializer<Date>() { public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { return new Date(json.getAsJsonPrimitive().getAsLong()); } });*/ this.mapper = builder.setPrettyPrinting().create(); if (sslEnabled) this.httpClient = getHttpClientForSsl(); else this.httpClient = HttpClientBuilder.create().setDefaultRequestConfig(config) .setConnectionManager(new PoolingHttpClientConnectionManager()).build(); }
From source file:org.opencrx.application.bpi.adapter.BpiPlugIn.java
License:BSD License
/** * Stringify value./* ww w .j a v a2s . c o m*/ * * @param value * @param prettyPrinting */ public String printObject(Object value, boolean prettyPrinting) { GsonBuilder gsonBuilder = this.newGsonBuilder(); if (prettyPrinting) { gsonBuilder.setPrettyPrinting(); } Gson gson = gsonBuilder.create(); return gson.toJson(value); }
From source file:org.openlaszlo.remote.json.LZGsonMarshaller.java
License:Open Source License
@Override public byte[] createObject(Object object, String objectReturnType) { try {/*w w w . 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.ppojo.data.Serializer.java
License:Apache License
private void CreateNewSerializer() { GsonBuilder builder = new GsonBuilder(); builder.registerTypeAdapter(ArtifactData.class, _artifactSerializer); builder.registerTypeAdapter(TemplateFileData.class, _templateSerializer); builder.registerTypeAdapter(CopyStyleData[].class, _copyStyleDataSerializer); builder = getIsPretty() ? builder.setPrettyPrinting() : builder; _gsonCustomized = builder.create();/* w ww. j a va 2 s.c o m*/ builder = new GsonBuilder(); builder = getIsPretty() ? builder.setPrettyPrinting() : builder; _gsonRegular = builder.create(); _artifactSerializer.setGson(_gsonRegular); _templateSerializer.setGson(_gsonRegular); _copyStyleDataSerializer.setGson(_gsonRegular); }
From source file:org.ramadda.repository.output.JsonOutputHandler.java
License:Apache License
/** * _more_/*w w w.ja v a 2 s .c om*/ * * @param args _more_ */ public static void main(String[] args) { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.setPrettyPrinting(); gsonBuilder.setDateFormat(DateFormat.LONG); gsonBuilder.setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE); Gson gson = gsonBuilder.create(); Entry entry = new Entry(); System.err.println(gson.toJson(entry)); }
From source file:org.raspinloop.config.GsonProperties.java
License:Apache License
public GsonProperties(HardwareEnumerator enumerator) { GsonBuilder builder = new GsonBuilder(); Collection<HardwareProperties> boards = enumerator.buildListImplementing(BoardHardware.class); boolean delegateExisting = false; for (HardwareProperties hardwareProps : boards) { if (hardwareProps instanceof BoardHardwareDelegate) { delegateExisting = true;/*from w w w . java 2s .c o m*/ } } if (!delegateExisting) boards.add(new BoardHardwareDelegate()); builder = registerImpl(boards, builder, BoardHardware.class); builder = registerImpl(enumerator.buildListImplementing(BoardExtentionHardware.class), builder, BoardExtentionHardware.class); builder = registerImpl(enumerator.buildListImplementing(UARTComponent.class), builder, UARTComponent.class); builder = registerImpl(enumerator.buildListImplementing(I2CComponent.class), builder, I2CComponent.class); builder = registerImpl(enumerator.buildListImplementing(SPIComponent.class), builder, SPIComponent.class); builder.registerTypeAdapter(Pin.class, new InstanceCreator<PinImpl>() { public PinImpl createInstance(Type type) { return new PinImpl(); } }); builder.setExclusionStrategies(new PreventLoop()); gsonExt = builder.setPrettyPrinting().create(); }
From source file:org.restcomm.connect.http.AccountsEndpoint.java
License:Open Source License
@PostConstruct void init() {//from w w w. j av a2 s . c o m rootConfiguration = (Configuration) context.getAttribute(Configuration.class.getName()); runtimeConfiguration = rootConfiguration.subset("runtime-settings"); super.init(runtimeConfiguration); clientDao = ((DaoManager) context.getAttribute(DaoManager.class.getName())).getClientsDao(); final AccountConverter converter = new AccountConverter(runtimeConfiguration); final GsonBuilder builder = new GsonBuilder(); builder.registerTypeAdapter(Account.class, converter); builder.setPrettyPrinting(); gson = builder.create(); xstream = new XStream(); xstream.alias("RestcommResponse", RestCommResponse.class); xstream.registerConverter(converter); xstream.registerConverter(new AccountListConverter(runtimeConfiguration)); xstream.registerConverter(new RestCommResponseConverter(runtimeConfiguration)); // Make sure there is an authenticated account present when this endpoint is used checkAuthenticatedAccount(); }
From source file:org.restcomm.connect.http.AvailablePhoneNumbersEndpoint.java
License:Open Source License
@PostConstruct public void init() throws ObjectInstantiationException { configuration = (Configuration) context.getAttribute(Configuration.class.getName()); super.init(configuration.subset("runtime-settings")); /*/* w ww .j a v a 2 s . c o m*/ 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); } */ // get manager from context or create it if it does not exist phoneNumberProvisioningManager = new PhoneNumberProvisioningManagerProvider(configuration, context).get(); xstream = new XStream(); xstream.alias("RestcommResponse", RestCommResponse.class); xstream.registerConverter(new AvailablePhoneNumberConverter(configuration)); xstream.registerConverter(new AvailablePhoneNumberListConverter(configuration)); xstream.registerConverter(new RestCommResponseConverter(configuration)); final GsonBuilder builder = new GsonBuilder(); builder.setPrettyPrinting(); // builder.serializeNulls(); gson = builder.create(); }
From source file:org.restcomm.connect.http.ExtensionsConfigurationEndpoint.java
License:Open Source License
@PostConstruct void init() {/* w ww .j a va 2 s . co m*/ allConfiguration = (Configuration) context.getAttribute(Configuration.class.getName()); configuration = allConfiguration.subset("runtime-settings"); super.init(configuration); extensionsConfigurationDao = ((DaoManager) context.getAttribute(DaoManager.class.getName())) .getExtensionsConfigurationDao(); final ExtensionConfigurationConverter converter = new ExtensionConfigurationConverter(configuration); final GsonBuilder builder = new GsonBuilder(); builder.registerTypeAdapter(ExtensionConfiguration.class, converter); builder.setPrettyPrinting(); gson = builder.create(); xstream = new XStream(); xstream.alias("RestcommResponse", RestCommResponse.class); xstream.registerConverter(converter); xstream.registerConverter(new ExtensionConfigurationConverter(configuration)); xstream.registerConverter(new RestCommResponseConverter(configuration)); // Make sure there is an authenticated account present when this endpoint is used checkAuthenticatedAccount(); }
From source file:org.restcomm.connect.http.GeolocationEndpoint.java
License:Open Source License
@PostConstruct public void init() { final DaoManager storage = (DaoManager) context.getAttribute(DaoManager.class.getName()); dao = storage.getGeolocationDao();// w w w . j a v a 2s . c om accountsDao = storage.getAccountsDao(); configuration = (Configuration) context.getAttribute(Configuration.class.getName()); configuration = configuration.subset("runtime-settings"); super.init(configuration); final GeolocationConverter converter = new GeolocationConverter(configuration); final GsonBuilder builder = new GsonBuilder(); builder.registerTypeAdapter(Geolocation.class, converter); builder.setPrettyPrinting(); gson = builder.create(); xstream = new XStream(); xstream.alias("RestcommResponse", RestCommResponse.class); xstream.registerConverter(converter); xstream.registerConverter(new ClientListConverter(configuration)); xstream.registerConverter(new GeolocationListConverter(configuration)); xstream.registerConverter(new RestCommResponseConverter(configuration)); }