Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How do you register @XmlAnyElement property in Confluence DTOs without UnrecognizedPropertyException

Nathaniel Jennings November 7, 2019

Annotation 2019-11-07 114905.png

I have an Atlassian Rest endpoint which accepts class A and correctly maps JSON properties to class properties as expected from a JSON POST from a Restful AUI table. Annotation 2019-11-07 114905.png

Now I need to add extra, unknown, fields like "FriendsWithNate" to the POST request and have access to these properties within the Rest endpoint without specifically including these unknown properties in the class definition and without triggering an exception:

org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field [FriendsWithNate]

I want the properties that I have mapped already to continue to work as normal, but if there are extra fields in the JSON request I would like those to be available to me in the endpoint as well. The endpoint body will know about the names of fields to look for as they are stored in plugin settings, but class A will just need to be able to handle those extra fields somehow so the class can actually reach the endpoint without causing an exception.

 

Forums have suggested this Catch-all XmlAnyElement annotation which aggregates unknown fields into a list as explained in the documentation below.

Annotation 2019-11-07 114905.png

https://docs.oracle.com/javase/8/docs/api/javax/xml/bind/annotation/XmlAnyElement.html

 

I am not sure if the XmlAnyElement solution works, because my request hasn't arrived at the endpoint yet due to the exception at the top of this question. Unrecognized Field. Now to add this JsonIgnoreProperties to hopefully suppress the Exception. Nothing ChangedDidn't Work. Still An Exception.

 

I would like to maintain the current signature of this endpoint, because it has XML/JSON reading built in. I understand the ease of changing the endpoint to accept a HttpServletRequest instead and get req.getParameter() all the properties I need, but it defeats the XML/JSON request requirement.

Let me know if you have any suggestions and would prefer some more detailed information (code) in an email or other medium.

 

 

 

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events