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.tuleap.mylyn.task.core.internal.parser.TuleapGsonProvider.java
License:Open Source License
/** * Provides the default {@link GsonBuilder}. * * @return A new instance of GsonBuilder, properly configured for Tuleap. *//* ww w.j a va2 s . c o m*/ public static GsonBuilder defaultBuilder() { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.registerTypeAdapter(TuleapTracker.class, new TuleapTrackerDeserializer()); gsonBuilder.registerTypeAdapter(TuleapElementComment.class, new TuleapChangesetDeserializer()); gsonBuilder.registerTypeAdapter(TuleapWorkflowTransition.class, new TuleapWorkflowTransitionDeserializer()); gsonBuilder.registerTypeAdapter(Date.class, new DateIso8601Adapter()); gsonBuilder.registerTypeAdapter(TuleapArtifact.class, new TuleapArtifactDeserializer()); gsonBuilder.registerTypeAdapter(TuleapArtifact.class, new TuleapArtifactSerializer()); gsonBuilder.registerTypeAdapter(TuleapArtifactWithComment.class, new TuleapArtifactWithCommentSerializer<TuleapArtifactWithComment>()); gsonBuilder.registerTypeAdapter(TuleapArtifactWithAttachment.class, new TuleapArtifactWithAttachmentSerializer()); gsonBuilder.registerTypeAdapter(ArtifactLinkFieldValue.class, new ArtifactLinkFieldValueAdapter()); gsonBuilder.registerTypeAdapter(LiteralFieldValue.class, new LiteralFieldValueSerializer()); gsonBuilder.registerTypeAdapter(AttachmentFieldValue.class, new AttachmentFieldValueAdapter()); gsonBuilder.registerTypeAdapter(BoundFieldValue.class, new BoundFieldValueSerializer()); gsonBuilder.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES); gsonBuilder.serializeNulls(); return gsonBuilder; }
From source file:org.uorm.serializer.DefaultJsonSerializer.java
License:Apache License
/** * @return the gson//from w w w . ja v a 2s . c o m */ public Gson getGson() { if (gson == null) { GsonBuilder gbuilder = new GsonBuilder(); if (serializeNulls) { gbuilder.serializeNulls(); } gbuilder.setDateFormat(datePattern); if (prettyPrinting) { gbuilder.setPrettyPrinting(); } if (excludeFieldsWithoutExposeAnnotation) { gbuilder.excludeFieldsWithoutExposeAnnotation(); } if (enableComplexMapKey) { gbuilder.enableComplexMapKeySerialization(); } if (version != null) { gbuilder.setVersion(version); } gson = gbuilder.create(); } return gson; }
From source file:org.wooden.util.GsonConf.java
License:Open Source License
private static Gson createGson() { GsonBuilder gb = new GsonBuilder(); gb.serializeNulls(); gb.setPrettyPrinting();/*w w w . j a v a 2 s. co m*/ return gb.create(); }
From source file:org.xjava.gsonrpc.GsonRPC.java
License:Open Source License
/** * Constructs an instance of GsonRPC using a supplied GsonBuilder. This allows you to register any custom Gson * serializers/deserializers you will need (all other GsonBuilder options may be overwritten). * * <p>To initialize GsonRPC with a GsonBuilder use the following code:</p> * * <pre>{@code/* www. j a v a 2 s . c o m*/ * GsonBuilder gsonBuilder = new GsonBuilder(); * gsonBuilder.registerTypeAdapter(CustomType.class, new CustomTypeSerializer()); //OPTIONAL * gsonBuilder.registerTypeAdapter(CustomType.class, new CustomTypeDeserializer()); //OPTIONAL * GsonRPC gsonRPC = new GsonRPC(gsonBuilder); * }</pre> * * <p>NOTE: Be sure to use gsonBuilder.registerTypeAdapter(type, typeAdapter) to register any custom * serializers/deserializers you will need before passing gsonBuilder to GsonRPC.</p> * * @param gsonBuilder The GsonBuilder */ public GsonRPC(GsonBuilder gsonBuilder) { gson = gsonBuilder.serializeNulls() .registerTypeAdapter(JsonRPCMessage.class, new JsonRPCMessageDeserializer()) .registerTypeAdapter(JsonRPCRequest.class, new JsonRPCRequestSerializer()) .registerTypeAdapter(JsonRPCResponse.class, new JsonRPCResponseSerializer()) .registerTypeAdapter(JsonRPCErrorResponse.class, new JsonRPCErrorResponseSerializer()).create(); messageFactory = new JsonRPCMessageFactory(gson); proxyFactory = new JsonRPCProxyFactory(this); requestHandler = new JsonRPCRequestHandler(gson, messageFactory); }
From source file:se.sperber.cryson.serialization.CrysonSerializer.java
License:Apache License
@PostConstruct public void setupGson() { jsonParser = new JsonParser(); GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.serializeNulls(); gsonBuilder.setDateFormat("yyyy-MM-dd HH:mm:ss Z"); HibernateProxyTypeAdapter hibernateProxyTypeAdapter = new HibernateProxyTypeAdapter(); gsonBuilder.registerTypeHierarchyAdapter(HibernateProxy.class, hibernateProxyTypeAdapter); gsonAllInclusive = gsonBuilder.create(); gsonBuilder.setExclusionStrategies(lazyAssociationExclusionStrategy, userTypeExclusionStrategy, crysonExcludeExclusionStrategy); gson = gsonBuilder.create();/*from w w w . j a va 2 s. c o m*/ hibernateProxyTypeAdapter.setGson(gson); }
From source file:utilty.means.utils.GsonUtils.java
License:Open Source License
/** * Create the standard {@link Gson} configuration * * @param serializeNulls/*from ww w. jav a 2 s. c o m*/ * whether nulls should be serialized * * @return created gson, never null */ public static final Gson createGson(final boolean serializeNulls) { final GsonBuilder builder = new GsonBuilder(); if (serializeNulls) builder.serializeNulls(); return builder.create(); }
From source file:view.GsonView.java
public static Gson CreateGson(boolean serializeNuls, String dateformat) { GsonBuilder gb = new GsonBuilder(); if (serializeNuls) { gb = gb.serializeNulls(); }// w w w.j a va 2 s . co m if ((dateformat != null) && (!dateformat.isEmpty())) { gb = gb.setDateFormat(dateformat); } return gb.create(); }