Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

How to change JsonInclude.Include.NOT_NULL to JsonInclude.Include.ALWAYS #416

Open
sravanthik07 opened this issue Dec 16, 2019 · 9 comments

Comments

@sravanthik07
Copy link

sravanthik07 commented Dec 16, 2019

Hi,
I have requirement to print 'null' values in json response. For that the generated java classes should @JsonInclude(JsonInclude.Include.ALWAYS).
I tried to get some help inn searching across the git but I found "NOT_NULL" is hard coded in "JacksonBasicExtension".
Please help us to find the solution.
image

@jpbelang
Copy link
Contributor

You may be going about this the wrong way. Should I do what you want, you would be breaking the RAML spec:
Your declaration should be

types:
   mytype:
      billingAccountId:  string | nil

I'll check with the parser to make sure.
Otherwise, there are two ways to do this:

  1. Redefine the contents of the jackson plugin by having a META-INF/ramltopojo-plugin.properties file with your own plugin definition like:
myown.jackson2=\
            myown.jacksonfix.JacksonBasicExtension,\
            org.raml.ramltopojo.extensions.jackson2.JacksonDiscriminatorInheritanceTypeExtension,\
            org.raml.ramltopojo.extensions.jackson2.JacksonScalarTypeSerialization,\
            org.raml.ramltopojo.extensions.jackson2.JacksonUnionExtension,\
            org.raml.ramltopojo.extensions.jackson2.JacksonEnumExtension,\
            org.raml.ramltopojo.extensions.jackson2.JacksonAdditionalProperties

The myown.jacksonfix.JacksonBasicExtension would contain the fixed JacksonBasicExtension code.

  1. You could write you own plugin that could fix the annotation so that you get what you want.

I'll get back to you on thursday.

@sravanthik07
Copy link
Author

Hi JP Belanger,
Thank you for the quick response.
I tried this option - billingAccountId: string | nil
Exception on maven build :
Error generating Java classes from: null: can't fetch type named string | nil

I will try the other approach's too.

@jpbelang
Copy link
Contributor

jpbelang commented Dec 19, 2019

Yes, the string|nil fix was recently fixed. try the current snapshot version from the mulesoft maven repository.

I'm going to be releasing it next week.

@sravanthik07
Copy link
Author

sravanthik07 commented Dec 21, 2019

Ok sure. I will check on it.
We have another use case to solve.
Here is the screenshot:
image

Any way that RAML can add schema to the XML payload? How to get rid of wrappers in xml payload?

@sravanthik07
Copy link
Author

Hi @jpbelang ,
Any clues on adding schema to XML payload?

@jpbelang
Copy link
Contributor

Sorry, got Christmassed.

Looking now.

@jpbelang
Copy link
Contributor

jpbelang commented Dec 26, 2019

@sravanthik07
Copy link
Author

I think, this will help, but i have to construct the response payload based on the ACCEPT.MEDIATYPE from Request headers. For example, if ACCEPT is json, the following code should give me JSON payload. But since, the Person if having xml attribute, will json works here?
types:
Person:
properties:
name:
type: string
xml:
attribute: true # serialize it as an XML attribute
name: "fullname" # attribute should be called fullname
addresses:
type: Address[]
xml:
wrapped: true # serialize it into its own ... XML element

@jpbelang
Copy link
Contributor

The annotations are on the data objects. The serialization should depend on the incoming HTTP headers.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants