-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
[java-client][rest-assured] add jackson support in addition to gson #3795
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
Merged
jmini
merged 5 commits into
OpenAPITools:master
from
jmini:issue3570-restassured-jackson
Aug 29, 2019
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
60a57d9
[java-client][rest-assured] add jackson support in addition to gson
jmini 7c715e6
Update samples
jmini 9ceed27
Fix jackson version in the description
jmini 91fb16e
Update docs
jmini b70711d
Use rest-assured TypeRef instead of jackson TypeFactory
jmini File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...api-generator/src/main/resources/Java/libraries/rest-assured/JacksonObjectMapper.mustache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| {{>licenseInfo}} | ||
|
|
||
| package {{invokerPackage}}; | ||
|
|
||
| {{#threetenbp}} | ||
| import org.threeten.bp.*; | ||
| {{/threetenbp}} | ||
| import com.fasterxml.jackson.annotation.*; | ||
| import com.fasterxml.jackson.databind.*; | ||
| import org.openapitools.jackson.nullable.JsonNullableModule; | ||
| {{#java8}} | ||
| import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; | ||
| {{/java8}} | ||
| {{#joda}} | ||
| import com.fasterxml.jackson.datatype.joda.JodaModule; | ||
| {{/joda}} | ||
| {{#threetenbp}} | ||
| import com.fasterxml.jackson.datatype.threetenbp.ThreeTenModule; | ||
| {{/threetenbp}} | ||
|
|
||
| import io.restassured.internal.mapping.Jackson2Mapper; | ||
| import io.restassured.path.json.mapper.factory.Jackson2ObjectMapperFactory; | ||
|
|
||
|
|
||
| public class JacksonObjectMapper extends Jackson2Mapper { | ||
|
|
||
| private JacksonObjectMapper() { | ||
| super(createFactory()); | ||
| } | ||
|
|
||
| private static Jackson2ObjectMapperFactory createFactory() { | ||
| return (cls, charset) -> { | ||
| ObjectMapper mapper = new ObjectMapper(); | ||
| mapper = new ObjectMapper(); | ||
| mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); | ||
| mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); | ||
| mapper.configure(DeserializationFeature.FAIL_ON_INVALID_SUBTYPE, false); | ||
| mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); | ||
| mapper.enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING); | ||
| mapper.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING); | ||
| mapper.setDateFormat(new RFC3339DateFormat()); | ||
| {{#java8}} | ||
| mapper.registerModule(new JavaTimeModule()); | ||
| {{/java8}} | ||
| {{#joda}} | ||
| mapper.registerModule(new JodaModule()); | ||
| {{/joda}} | ||
| {{#threetenbp}} | ||
| ThreeTenModule module = new ThreeTenModule(); | ||
| module.addDeserializer(Instant.class, CustomInstantDeserializer.INSTANT); | ||
| module.addDeserializer(OffsetDateTime.class, CustomInstantDeserializer.OFFSET_DATE_TIME); | ||
| module.addDeserializer(ZonedDateTime.class, CustomInstantDeserializer.ZONED_DATE_TIME); | ||
| mapper.registerModule(module); | ||
| {{/threetenbp}} | ||
| JsonNullableModule jnm = new JsonNullableModule(); | ||
| mapper.registerModule(jnm); | ||
| return mapper; | ||
| }; | ||
| } | ||
|
|
||
| public static JacksonObjectMapper jackson() { | ||
| return new JacksonObjectMapper(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.