-
Notifications
You must be signed in to change notification settings - Fork 38.5k
SPR-9488 Add GsonHttpMessageConverter #493
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
public GsonHttpMessageConverter(GsonBuilder gsonBuilder) { | ||
super(new MediaType("application", "json", DEFAULT_CHARSET), | ||
new MediaType("application", "*+json", DEFAULT_CHARSET)); | ||
Assert.notNull(gsonBuilder, "'gson' must not be null"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe it should be 'gsonBuilder' must not be null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected this in the updated PR. Thanks for reviewing!
rebased against the latest changes from master and fixed merge issues |
@Override | ||
public JsonElement serialize(byte[] src, Type typeOfSrc, | ||
JsonSerializationContext context) { | ||
return new JsonPrimitive(new String(Base64.getEncoder().encode(src), DEFAULT_CHARSET)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Realized I used the Java 8 Base64 encoder. This needs to be reworked to remove the Java 8 dependency.
rebased against master and fixed merge issues |
Removed the dependency on Java 8 Base64 in favor of commons-codec. |
Added GsonFactoryBean, which migrates many of the convenience properties away from GsonHttpMessageConverter. Updated commit and PR description. Rebased against master and fixed merge issues. cc: @rstoyanchev |
This commit adds support to read and write JSON using the Google Gson library. GsonHttpMessageConverter offers default Gson configuration, but can be customized by using GsonFactoryBean. GsonFactoryBean includes several convenience properties for configuring the internal GsonBuilder and the resulting Gson object. By default Gson converts byte arrays to JSON arrays instead of a Base64 encoded string. GsonBase64ByteArrayJsonTypeAdapter provides support to read and write Base64 encoded byte arrays, and can be enabled in GsonFactoryBean. RestTemplate will enable GsonHttpMessageConverter only if Jackson 2 is not found on the class path, because by default GsonHttpMessageConverter supports the same media types as Jackson. Issue: SPR-9488
Thanks Roy, this is now merged into master. I only added the converter to the MVC config much like it was already done in the RestTemplate. |
This commit adds support to read and write JSON using the Google Gson
library. GsonHttpMessageConverter offers default Gson configuration, but
can be customized by using GsonFactoryBean. GsonFactoryBean includes
several convenience properties for configuring the internal GsonBuilder
and the resulting Gson object.
By default Gson converts byte arrays to JSON arrays instead of a Base64
encoded string. GsonBase64ByteArrayJsonTypeAdapter provides support to
read and write Base64 encoded byte arrays, and can be enabled in
GsonFactoryBean.
RestTemplate will enable GsonHttpMessageConverter only if Jackson 2 is
not found on the class path, because by default GsonHttpMessageConverter
supports the same media types as Jackson.
Issue: SPR-9488