List of usage examples for com.google.gson GsonBuilder setPrettyPrinting
public GsonBuilder setPrettyPrinting()
From source file:org.ambraproject.rhino.config.RhinoConfiguration.java
License:Open Source License
/** * Gson instance for serializing Ambra entities into human-friendly JSON. *//*from w w w .jav a 2s . c om*/ @Bean public Gson entityGson(RuntimeConfiguration runtimeConfiguration) { GsonBuilder builder = JsonAdapterUtil.makeGsonBuilder(); if (runtimeConfiguration.prettyPrintJson()) { builder.setPrettyPrinting(); } // Bulk-apply special cases defined in org.ambraproject.rhino.config.json for (Class<? extends JsonOutputView> viewClass : AdapterRegistry.getOutputViewClasses()) { builder.registerTypeAdapter(viewClass, JsonOutputView.SERIALIZER); } for (Map.Entry<Type, Object> entry : AdapterRegistry.getCustomAdapters().entrySet()) { builder.registerTypeAdapter(entry.getKey(), entry.getValue()); } Java8TimeGsonAdapters.register(builder); return builder.create(); }
From source file:org.ambraproject.wombat.config.RootConfiguration.java
License:Open Source License
@Bean public Gson gson() { GsonBuilder builder = new GsonBuilder(); builder.setPrettyPrinting(); builder.registerTypeAdapter(Date.class, new Iso8601DateAdapter()); builder.registerTypeAdapter(org.joda.time.LocalDate.class, JodaTimeLocalDateAdapter.INSTANCE); return builder.create(); }
From source file:org.apache.abdera2.activities.io.gson.GsonIO.java
License:Apache License
static Gson gson(Boolean pretty, BaseAdapter asbs, Iterable<TypeAdapter<?>> adapters) { GsonBuilder gb = new GsonBuilder().registerTypeHierarchyAdapter(Verb.class, new VerbAdapter()) .registerTypeHierarchyAdapter(Lang.class, new LangAdapter()) .registerTypeHierarchyAdapter(ASBase.class, asbs) .registerTypeHierarchyAdapter(Multimap.class, new MultimapAdapter()) .registerTypeHierarchyAdapter(MimeType.class, new MimeTypeAdapter()) .registerTypeAdapter(ASBase.class, asbs).registerTypeAdapter(Date.class, new DateAdapter()) .registerTypeAdapter(DateTime.class, new DateTimeAdapter()) .registerTypeAdapter(Duration.class, new DurationAdapter()) .registerTypeAdapter(Interval.class, new IntervalAdapter()) .registerTypeAdapter(Activity.class, asbs).registerTypeAdapter(PlaceObject.class, asbs) .registerTypeAdapter(Mood.class, asbs).registerTypeAdapter(Address.class, asbs) .registerTypeAdapter(IRI.class, new IriAdapter()) .registerTypeAdapter(IsoPosition.class, new PositionAdapter()) .registerTypeAdapter(EntityTag.class, new EntityTagAdapter()) .registerTypeAdapter(Template.class, new TemplateAdapter()) .registerTypeAdapter(MimeType.class, new MimeTypeAdapter()); for (TypeAdapter<?> adapter : adapters) if (adapter instanceof GsonTypeAdapter) gb.registerTypeAdapter(adapter.getAdaptedClass(), adapter); gb.enableComplexMapKeySerialization(); if (pretty)/*from ww w . j ava 2 s. c o m*/ gb.setPrettyPrinting(); return gb.create(); }
From source file:org.apache.camel.component.gson.GsonDataFormat.java
License:Apache License
@Override protected void doStart() throws Exception { if (gson == null) { GsonBuilder builder = new GsonBuilder(); if (exclusionStrategies != null && !exclusionStrategies.isEmpty()) { ExclusionStrategy[] strategies = exclusionStrategies .toArray(new ExclusionStrategy[exclusionStrategies.size()]); builder.setExclusionStrategies(strategies); }/*from w w w. java2s. c om*/ if (longSerializationPolicy != null) { builder.setLongSerializationPolicy(longSerializationPolicy); } if (fieldNamingPolicy != null) { builder.setFieldNamingPolicy(fieldNamingPolicy); } if (fieldNamingStrategy != null) { builder.setFieldNamingStrategy(fieldNamingStrategy); } if (serializeNulls != null && serializeNulls) { builder.serializeNulls(); } if (prettyPrinting != null && prettyPrinting) { builder.setPrettyPrinting(); } if (dateFormatPattern != null) { builder.setDateFormat(dateFormatPattern); } gson = builder.create(); } }
From source file:org.apache.kerby.kerberos.kdc.identitybackend.JsonIdentityBackend.java
License:Apache License
private void initGsonBuilder() { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.registerTypeAdapter(EncryptionKey.class, new EncryptionKeyAdapter()); gsonBuilder.registerTypeAdapter(PrincipalName.class, new PrincipalNameAdapter()); gsonBuilder.registerTypeAdapter(KerberosTime.class, new KerberosTimeAdapter()); gsonBuilder.enableComplexMapKeySerialization(); gsonBuilder.setPrettyPrinting(); gson = gsonBuilder.create();/*from w w w . j a v a2 s. c o m*/ }
From source file:org.apache.mahout.classifier.sgd.LogisticModelParameters.java
License:Apache License
/** * Saves a model in JSON format. This includes the current state of the logistic regression * trainer and the dictionary for the target categories. * * @param out Where to write the model./*from w w w . j av a2 s.c o m*/ * @throws IOException */ public void saveTo(Writer out) throws IOException { if (lr != null) { lr.close(); } targetCategories = csv.getTargetCategories(); GsonBuilder gb = new GsonBuilder(); gb.registerTypeAdapter(Matrix.class, new MatrixTypeAdapter()); Gson gson = gb.setPrettyPrinting().create(); String savedForm = gson.toJson(this); out.write(savedForm); }
From source file:org.apache.tika.metadata.serialization.JsonMetadataBase.java
License:Apache License
static Gson prettyInit() { GsonBuilder builder = new GsonBuilder(); builder.registerTypeHierarchyAdapter(Metadata.class, new SortedJsonMetadataSerializer()); builder.registerTypeHierarchyAdapter(Metadata.class, new JsonMetadataDeserializer()); builder.setPrettyPrinting(); return builder.create(); }
From source file:org.apache.zeppelin.interpreter.InterpreterFactory.java
License:Apache License
public InterpreterFactory(ZeppelinConfiguration conf, InterpreterOption defaultOption, AngularObjectRegistryListener angularObjectRegistryListener) throws InterpreterException, IOException { this.conf = conf; this.defaultOption = defaultOption; this.angularObjectRegistryListener = angularObjectRegistryListener; String replsConf = conf.getString(ConfVars.ZEPPELIN_INTERPRETERS); interpreterClassList = replsConf.split(","); GsonBuilder builder = new GsonBuilder(); builder.setPrettyPrinting(); builder.registerTypeAdapter(Interpreter.class, new InterpreterSerializer()); gson = builder.create();/*from w ww . j av a 2 s . c om*/ init(); }
From source file:org.apache.zeppelin.interpreter.InterpreterFactory.java
License:Apache License
private void loadFromFile() throws IOException { GsonBuilder builder = new GsonBuilder(); builder.setPrettyPrinting(); builder.registerTypeAdapter(Interpreter.class, new InterpreterSerializer()); Gson gson = builder.create();/*from w w w. ja va 2 s. c om*/ File settingFile = new File(conf.getInterpreterSettingPath()); if (!settingFile.exists()) { // nothing to read return; } FileInputStream fis = new FileInputStream(settingFile); InputStreamReader isr = new InputStreamReader(fis); BufferedReader bufferedReader = new BufferedReader(isr); StringBuilder sb = new StringBuilder(); String line; while ((line = bufferedReader.readLine()) != null) { sb.append(line); } isr.close(); fis.close(); String json = sb.toString(); InterpreterInfoSaving info = gson.fromJson(json, InterpreterInfoSaving.class); for (String k : info.interpreterSettings.keySet()) { InterpreterSetting setting = info.interpreterSettings.get(k); // Always use separate interpreter process // While we decided to turn this feature on always (without providing // enable/disable option on GUI). // previously created setting should turn this feature on here. setting.getOption().setRemote(true); InterpreterSetting intpSetting = new InterpreterSetting(setting.id(), setting.getName(), setting.getGroup(), setting.getOption()); InterpreterGroup interpreterGroup = createInterpreterGroup(setting.id(), setting.getGroup(), setting.getOption(), setting.getProperties()); intpSetting.setInterpreterGroup(interpreterGroup); interpreterSettings.put(k, intpSetting); } this.interpreterBindings = info.interpreterBindings; }
From source file:org.apache.zeppelin.notebook.Notebook.java
License:Apache License
/** * Export existing note.//from ww w. java 2 s .co m * * @param noteId - the note ID to clone * @return Note JSON * @throws IOException, IllegalArgumentException */ public String exportNote(String noteId) throws IOException, IllegalArgumentException { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.setPrettyPrinting(); Gson gson = gsonBuilder.create(); Note note = getNote(noteId); if (note == null) { throw new IllegalArgumentException(noteId + " not found"); } return gson.toJson(note); }