List of usage examples for com.google.gson GsonBuilder enableComplexMapKeySerialization
public GsonBuilder enableComplexMapKeySerialization()
From source file:com.devamatre.core.JSONHelper.java
License:Open Source License
/** * Returns the GSON object.//from w w w . java 2s. c o m * * @param prettyPrint * @return */ private static Gson newGsonObject(boolean prettyPrint) { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.enableComplexMapKeySerialization(); if (prettyPrint) { gsonBuilder.setPrettyPrinting(); } Gson gson = gsonBuilder.create(); return gson; }
From source file:com.hybris.datahub.outbound.utils.CommonUtils.java
License:Open Source License
/** * @param whetherExposeAnnotation/*from ww w. j a v a 2s . c o m*/ * @param dateFormat * @return Gson instance */ public static Gson getGsonByBuilder(final boolean whetherExposeAnnotation, String dateFormat) { final GsonBuilder gsonBuilder = new GsonBuilder(); if (whetherExposeAnnotation) { gsonBuilder.excludeFieldsWithoutExposeAnnotation(); } gsonBuilder.enableComplexMapKeySerialization(); if (StringUtils.isEmpty(dateFormat)) { dateFormat = "yyyy-MM-dd HH:mm:ss"; } gsonBuilder.serializeNulls().setDateFormat(dateFormat); gsonBuilder.setVersion(1.0); // gsonBuilder.disableHtmlEscaping(); return gsonBuilder.create(); }
From source file:io.weba.processor.flink.event.gson.factory.EventFactory.java
License:Open Source License
public Gson create() { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.registerTypeAdapter(Id.class, new IdSerializer()); gsonBuilder.registerTypeAdapter(Type.class, new TypeSerializer()); gsonBuilder.registerTypeAdapter(Visitor.class, new VisitorSerializer()); gsonBuilder.registerTypeAdapter(Session.class, new SessionSerializer()); gsonBuilder.registerTypeAdapter(Map.class, new MapSerializer()); gsonBuilder.registerTypeAdapter(Payload.class, new MapSerializer()); gsonBuilder.serializeNulls();/*from w ww. java2 s . c o m*/ gsonBuilder.setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); gsonBuilder.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES); gsonBuilder.setLongSerializationPolicy(LongSerializationPolicy.STRING); gsonBuilder.enableComplexMapKeySerialization(); return gsonBuilder.create(); }
From source file:it.newfammulfin.api.util.GsonReaderWriter.java
public GsonReaderWriter() { //should probably inject or something similar GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.registerTypeAdapter(Money.class, new MoneyConverter()); gsonBuilder.registerTypeAdapter(LocalDate.class, new LocalDateConverter()); gsonBuilder.registerTypeAdapter(CurrencyUnit.class, new CurrencyUnitConverter()); gsonBuilder.registerTypeAdapter(Key.class, new KeyConverter()); gsonBuilder.enableComplexMapKeySerialization(); gson = gsonBuilder.create();//from ww w .ja v a 2s. c o m }
From source file:net.ftb.workers.AuthlibHelper.java
License:Apache License
private static String encode(Map<String, Object> m) { try {//from w w w . j a v a 2 s . c o m Gson gson; final GsonBuilder builder = new GsonBuilder(); builder.registerTypeAdapterFactory(new EnumAdaptorFactory()); builder.registerTypeAdapter(Date.class, new DateAdapter()); builder.registerTypeAdapter(File.class, new FileAdapter()); builder.enableComplexMapKeySerialization(); builder.setPrettyPrinting(); gson = builder.create(); return gson.toJson(m); } catch (Exception e) { Logger.logError("Error encoding Authlib JSON", e); return null; } }
From source file:net.minecraft.client.versionRqst.java
public versionRqst() { GsonBuilder builder = new GsonBuilder(); builder.registerTypeAdapterFactory(new LowerCaseEnumTypeAdapterFactory()); builder.registerTypeAdapter(Date.class, new DateTypeAdapter()); builder.enableComplexMapKeySerialization(); builder.setPrettyPrinting();/*from ww w .j a v a 2s. c o m*/ this.gson = 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)/* w w w .j a va 2s .c om*/ gb.setPrettyPrinting(); return gb.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();/* ww w. j av a 2 s . com*/ gson = gsonBuilder.create(); }
From source file:org.eclipse.epp.internal.logging.aeri.ui.utils.Json.java
License:Open Source License
static synchronized Gson getInstance() { if (gson == null) { final GsonBuilder builder = new GsonBuilder(); builder.registerTypeAdapter(UUID.class, new UuidTypeAdapter()); builder.enableComplexMapKeySerialization(); builder.setPrettyPrinting();/*ww w. ja v a 2 s . c o m*/ gson = builder.create(); } return gson; }
From source file:org.eclipse.recommenders.utils.gson.GsonUtil.java
License:Open Source License
public static synchronized Gson getInstance() { if (gson == null) { final GsonBuilder builder = new GsonBuilder(); builder.registerTypeAdapter(VmMethodName.class, new MethodNameTypeAdapter()); builder.registerTypeAdapter(IMethodName.class, new MethodNameTypeAdapter()); builder.registerTypeAdapter(VmTypeName.class, new TypeNameTypeAdapter()); builder.registerTypeAdapter(ITypeName.class, new TypeNameTypeAdapter()); builder.registerTypeAdapter(VmFieldName.class, new FieldNameTypeAdapter()); builder.registerTypeAdapter(IFieldName.class, new FieldNameTypeAdapter()); builder.registerTypeAdapter(VmPackageName.class, new PackageNameTypeAdapter()); builder.registerTypeAdapter(IPackageName.class, new PackageNameTypeAdapter()); builder.registerTypeAdapter(File.class, new FileTypeAdapter()); builder.registerTypeAdapter(UUID.class, new UuidTypeAdapter()); builder.registerTypeAdapter(Date.class, new ISO8601DateParser()); builder.registerTypeAdapter(Multimap.class, new MultimapTypeAdapter()); builder.registerTypeAdapterFactory(new MultisetTypeAdapterFactory()); builder.enableComplexMapKeySerialization(); builder.setPrettyPrinting();/*from w w w. ja v a 2s . c o m*/ gson = builder.create(); } return gson; }