You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by "mark.cavender" <ma...@sbcglobal.net> on 2016/10/12 13:31:09 UTC

One to Many Relationship with Johnzon

Hi,

I'm trying to map a one to many relationship with Johnzon.  I have a User
class the points to an array of Role, as follows.

Class User {

String userName;

List<Role> roles = new ArrayList<>();

@JohnzonConverter( RoleAdapter.class)
public List<Role> getRoles() {

  return roles;
}

}

Class Role {
  String name;
  List<User> users;

  @JohnzonConverter(UserAdapter.class)
  public List<User> getUsers() {
    return users;
  }
}

I then have a converter defined as follows:

public class RoleAdapter implements Converter<Role> {

    @Override
    public String toString( final Role v ) {

        return v.getId().toString();
    }

    @Override
    public Role fromString( final String v ) {

        Role ri = new Role();
        ri.setId( Long.valueOf( v ) );
        return ri;
    }

}

I am trying to convert the list of a java object to an array of Strings of
the ID of that object.  The problem is that my Converter never gets called. 
I have tried moving the converter to the declaration as well, but it doesn't
seem to matter.  Is there something that needs to be done to register a
Converter with Johnzon?

Thanks in advance,

Mark



--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/One-to-Many-Relationship-with-Johnzon-tp4680322.html
Sent from the TomEE Users mailing list archive at Nabble.com.

Re: One to Many Relationship with Johnzon

Posted by "mark.cavender" <ma...@sbcglobal.net>.
Hi,

I was able to get it to work by changing the accessMode to "both" in the
resources.xml file.  I also took the quotes off johnzon in the
openejb-jar.xml file.  Thx for the help.

Mark



--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/One-to-Many-Relationship-with-Johnzon-tp4680322p4680326.html
Sent from the TomEE Users mailing list archive at Nabble.com.

Re: One to Many Relationship with Johnzon

Posted by Romain Manni-Bucau <rm...@gmail.com>.
have to admit I suggest it without checking so can be useless but try
removing the quotes around johnzon in providers value. Also check
ConfigurableJohnzonProvider
is listed in writers when starting up (logged at INFO level)


Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> |  Blog
<https://blog-rmannibucau.rhcloud.com> | Old Wordpress Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
<http://www.tomitribe.com> | JavaEE Factory
<https://javaeefactory-rmannibucau.rhcloud.com>

2016-10-12 15:58 GMT+02:00 mark.cavender <ma...@sbcglobal.net>:

> Thx for the quick reply,
>
> My openejb-jar.xml looks like this:
>
> <openejb-jar xmlns="http://www.openejb.org/openejb-jar/1.1">
>     <pojo-deployment class-name="jaxrs-application">
>         <properties>
>             cxf.jaxrs.providers = "johnzon"
>         </properties>
>     </pojo-deployment>
> </openejb-jar>
>
> and my resources.xml looks like this:
>
> <?xml version="1.0"?>
> <resources>
>     <Service id="johnzon"
> class-name="org.apache.johnzon.jaxrs.ConfigurableJohnzonProvider">
>         accessModeName = method
>         supportHiddenAccess = true
>         doCloseOnStreams = false
>         version = 2
>         skipNull = false
>         skipEmptyArray = false
>     </Service>
> </resources>
>
> This is the context for my webservices project.  I have the objects in
> another project that included.
>
>
>
> --
> View this message in context: http://tomee-openejb.979440.
> n4.nabble.com/One-to-Many-Relationship-with-Johnzon-tp4680322p4680324.html
> Sent from the TomEE Users mailing list archive at Nabble.com.
>

Re: One to Many Relationship with Johnzon

Posted by "mark.cavender" <ma...@sbcglobal.net>.
Thx for the quick reply,

My openejb-jar.xml looks like this:

<openejb-jar xmlns="http://www.openejb.org/openejb-jar/1.1">
    <pojo-deployment class-name="jaxrs-application">
        <properties>
            cxf.jaxrs.providers = "johnzon"
        </properties>
    </pojo-deployment>
</openejb-jar>

and my resources.xml looks like this:

<?xml version="1.0"?>
<resources>
    <Service id="johnzon"
class-name="org.apache.johnzon.jaxrs.ConfigurableJohnzonProvider">
        accessModeName = method
        supportHiddenAccess = true
        doCloseOnStreams = false
        version = 2
        skipNull = false
        skipEmptyArray = false
    </Service>
</resources>

This is the context for my webservices project.  I have the objects in
another project that included.



--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/One-to-Many-Relationship-with-Johnzon-tp4680322p4680324.html
Sent from the TomEE Users mailing list archive at Nabble.com.

Re: One to Many Relationship with Johnzon

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi Mark

this looks right (typically what we do in this test:
https://github.com/apache/johnzon/blob/b0af96e6d819adf7a28782ebc535894bd27345da/johnzon-mapper/src/test/java/org/apache/johnzon/mapper/ObjectConverterTest.java#L80
)

what's johnzon context (= sure you use johnzon)?


Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> |  Blog
<https://blog-rmannibucau.rhcloud.com> | Old Wordpress Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
<http://www.tomitribe.com> | JavaEE Factory
<https://javaeefactory-rmannibucau.rhcloud.com>

2016-10-12 15:31 GMT+02:00 mark.cavender <ma...@sbcglobal.net>:

> Hi,
>
> I'm trying to map a one to many relationship with Johnzon.  I have a User
> class the points to an array of Role, as follows.
>
> Class User {
>
> String userName;
>
> List<Role> roles = new ArrayList<>();
>
> @JohnzonConverter( RoleAdapter.class)
> public List<Role> getRoles() {
>
>   return roles;
> }
>
> }
>
> Class Role {
>   String name;
>   List<User> users;
>
>   @JohnzonConverter(UserAdapter.class)
>   public List<User> getUsers() {
>     return users;
>   }
> }
>
> I then have a converter defined as follows:
>
> public class RoleAdapter implements Converter<Role> {
>
>     @Override
>     public String toString( final Role v ) {
>
>         return v.getId().toString();
>     }
>
>     @Override
>     public Role fromString( final String v ) {
>
>         Role ri = new Role();
>         ri.setId( Long.valueOf( v ) );
>         return ri;
>     }
>
> }
>
> I am trying to convert the list of a java object to an array of Strings of
> the ID of that object.  The problem is that my Converter never gets called.
> I have tried moving the converter to the declaration as well, but it
> doesn't
> seem to matter.  Is there something that needs to be done to register a
> Converter with Johnzon?
>
> Thanks in advance,
>
> Mark
>
>
>
> --
> View this message in context: http://tomee-openejb.979440.
> n4.nabble.com/One-to-Many-Relationship-with-Johnzon-tp4680322.html
> Sent from the TomEE Users mailing list archive at Nabble.com.
>