Trouble Configuring Johnzon on 7.1

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Trouble Configuring Johnzon on 7.1

daveg-iwd
This is on Tomee plume 7.1:

I'm having trouble telling Johnzon to not generate json for methods.  I have
this class:

public class CheckUnqID  {

    @JohnzonProperty("UniqueID")
    private String UniqueID;

    public String getUniqueID() {
        return this.UniqueID;
    }

    public void setUniqueID(final String uniqueID) {
        this.UniqueID = uniqueID;
    }
}

The service I am talking to wants the field UniqueID to start with an
uppercase U (all of its fields in other resources have upper case first
letters).

This is the JSON that gets generated when doing a POST:

{"UniqueID":"hankventure1","uniqueID":"hankventure1"}

I've been trying to configure johnzon to only use fields. Based on the docs
at https://johnzon.apache.org/index.html I have this:

resources.xml

<?xml version="1.0" encoding="UTF-8"?>
<resources>
 <Service id="johnzon"
class-name="org.apache.johnzon.jaxrs.ConfigurableJohnzonProvider">
   accessModeName = field
   pretty = true
 </Service>
</resources>

openejb-jar.xml

<?xml version="1.0" encoding="UTF-8"?>
<openejb-jar xmlns="http://www.openejb.org/openejb-jar/1.1">
 <pojo-deployment class-name="jaxrs-application">
   <properties>
     cxf.jaxrs.providers =
johnzon,org.apache.openejb.server.cxf.rs.EJBAccessExceptionMapper
     cxf.jaxrs.skip-provider-scanning = true
   </properties>
 </pojo-deployment>
</openejb-jar>

I can see tomee reading the resources.xml as it deploys the app

Apr 19, 2019 8:24:19 AM org.apache.openejb.config.ConfigurationFactory
configureService
INFO: Configuring Service(id=johnzon, type=Service, provider-id=johnzon)
Apr 19, 2019 8:24:19 AM org.apache.openejb.config.ConfigurationFactory
configureService
FINE: [accessModeName=field]
Apr 19, 2019 8:24:19 AM org.apache.openejb.config.ConfigurationFactory
configureService
FINE: [pretty=true]

and yet it doesn't ever seem to get used.

Is there some other configuration I'm missing?

Also, is there some way to simply tell johnzon to use my field name exactly
as is without needing to tag each one with @JohnzonProperty?






--
Sent from: http://tomee-openejb.979440.n4.nabble.com/TomEE-Users-f979441.html
Reply | Threaded
Open this post in threaded view
|

Re: Trouble Configuring Johnzon on 7.1

Cesar Hernandez
Hi David,

I think all you need to do is to update the Property Naming Strategy.
Check out the following example:
https://tomee.apache.org/latest/examples/jsonb-configuration.html

To execute the example you need:
1) Clone the TomEE repo: https://github.com/apache/tomee
2) mvn clean install -DskipTests
3) mvn clean test -pl examples/jsonb-configuration

From there you can play around with the Property Naming Strategy:
https://github.com/apache/tomee/blob/master/examples/jsonb-configuration/src/main/java/org/superbiz/JSONBConfiguration.java#L20


El vie., 19 abr. 2019 a las 7:31, daveg-iwd (<[hidden email]>)
escribió:

> This is on Tomee plume 7.1:
>
> I'm having trouble telling Johnzon to not generate json for methods.  I
> have
> this class:
>
> public class CheckUnqID  {
>
>     @JohnzonProperty("UniqueID")
>     private String UniqueID;
>
>     public String getUniqueID() {
>         return this.UniqueID;
>     }
>
>     public void setUniqueID(final String uniqueID) {
>         this.UniqueID = uniqueID;
>     }
> }
>
> The service I am talking to wants the field UniqueID to start with an
> uppercase U (all of its fields in other resources have upper case first
> letters).
>
> This is the JSON that gets generated when doing a POST:
>
> {"UniqueID":"hankventure1","uniqueID":"hankventure1"}
>
> I've been trying to configure johnzon to only use fields. Based on the docs
> at https://johnzon.apache.org/index.html I have this:
>
> resources.xml
>
> <?xml version="1.0" encoding="UTF-8"?>
> <resources>
>  <Service id="johnzon"
> class-name="org.apache.johnzon.jaxrs.ConfigurableJohnzonProvider">
>    accessModeName = field
>    pretty = true
>  </Service>
> </resources>
>
> openejb-jar.xml
>
> <?xml version="1.0" encoding="UTF-8"?>
> <openejb-jar xmlns="http://www.openejb.org/openejb-jar/1.1">
>  <pojo-deployment class-name="jaxrs-application">
>    <properties>
>      cxf.jaxrs.providers =
> johnzon,org.apache.openejb.server.cxf.rs.EJBAccessExceptionMapper
>      cxf.jaxrs.skip-provider-scanning = true
>    </properties>
>  </pojo-deployment>
> </openejb-jar>
>
> I can see tomee reading the resources.xml as it deploys the app
>
> Apr 19, 2019 8:24:19 AM org.apache.openejb.config.ConfigurationFactory
> configureService
> INFO: Configuring Service(id=johnzon, type=Service, provider-id=johnzon)
> Apr 19, 2019 8:24:19 AM org.apache.openejb.config.ConfigurationFactory
> configureService
> FINE: [accessModeName=field]
> Apr 19, 2019 8:24:19 AM org.apache.openejb.config.ConfigurationFactory
> configureService
> FINE: [pretty=true]
>
> and yet it doesn't ever seem to get used.
>
> Is there some other configuration I'm missing?
>
> Also, is there some way to simply tell johnzon to use my field name exactly
> as is without needing to tag each one with @JohnzonProperty?
>
>
>
>
>
>
> --
> Sent from:
> http://tomee-openejb.979440.n4.nabble.com/TomEE-Users-f979441.html
>


--
Atentamente:
César Hernández.