[
https://issues.apache.org/jira/browse/JOHNZON-88?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15360249#comment-15360249
]
Jerome Doby commented on JOHNZON-88:
------------------------------------
Well thanks for your help on a Saturday.
I understand where you're coming from as far as the defaults go --
@XmlAccessorType defaults to public members, however the getter / setter
processing still feels like they are reversed to me.
When you hydrate something from JSON you would use the setter to set the
field's value, so you'd use the annotation on the setter.
When you serialize something to JSON you would use the getter to get the value
to be serialized, so you'd use the annotation on the getter.
Johnzon is doing it backwards :S
> Johnzon does not process Johnzon annotations when hydrating models using
> javax.ws.rs.client.Client
> --------------------------------------------------------------------------------------------------
>
> Key: JOHNZON-88
> URL: https://issues.apache.org/jira/browse/JOHNZON-88
> Project: Johnzon
> Issue Type: Improvement
> Components: JAX-RS
> Affects Versions: 0.9.3-incubating
> Environment: Server version: Apache Tomcat (TomEE)/8.5.2 (7.0.0)
> Server built: May 11 2016 21:49:07 UTC
> Server number: 8.5.2.0
> OS Name: Windows 10
> OS Version: 10.0
> Architecture: amd64
> Java Home: C:\Program Files\Java\home\jre
> JVM Version: 1.8.0_73-b02
> JVM Vendor: Oracle Corporation
> Reporter: Jerome Doby
> Priority: Minor
>
> According to the documentation at http://johnzon.apache.org/index.html,
> Johnzon is the default provider on TomEE 7.X, but it does not seem to process
> any Johnzon annotations when hydrating JSON responses using the default
> javax.ws.rs.client.Client implementation.
> Example:
> {code:title=Search.java|borderStyle=solid}
> package mypackage.models;
> import org.apache.johnzon.mapper.JohnzonProperty;
> public class Search
> {
> private Integer page;
> @JohnzonProperty( "total_pages" )
> private Integer totalPages;
> public Integer getPage()
> {
> return page;
> }
> public void setPage( Integer page )
> {
> this.page = page;
> }
> public Integer getTotalPages()
> {
> return totalPages;
> }
> public void setTotalPages( Integer totalPages )
> {
> this.totalPages = totalPages;
> }
> }
> {code}
> {code:title=Bootstrap.java|borderStyle=solid}
> package mypackage;
> import mypackage.models.Search;
> import javax.annotation.PostConstruct;
> import javax.ejb.Singleton;
> import javax.ejb.Startup;
> import javax.ws.rs.client.Client;
> import javax.ws.rs.client.ClientBuilder;
> @Singleton
> @Startup
> public class Bootstrap
> {
> private Client client;
> @PostConstruct
> private void postConstruct()
> {
> client = ClientBuilder.newClient();
> Search search = client.target( "http://someurl.json" )
> .request()
> .get( Search.class );
> }
> }
> {code}
> {code:title=Response.json|borderStyle=solid}
> {
> "page": 1,
> "total_pages": 114
> }
> {code}
> In this case, the field totalPages is null, but I would expect it to be 114.
> Is there something that I need to do to activate this behaviour? If so, can
> you add this information to the documentation?
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)