pascallouisperez / jsonmarshaller

JsonMarshaller is a Java 1.5 library that allows marshalling and unmarshalling of JSON objects to and from entities ("Java classes").
Apache License 2.0
1 stars 0 forks source link

marshalling defined for class should also work with collection of that class by only defining the annotation #28

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Entity:

@Entity
public class Complex {
  @Value(type = com.twolattes.json.types.URLType.class)
  public List<URL> urlList;

  public static void main(String args[]) {
    try{
    Complex c = new Complex();
    c.urlList = new ArrayList<URL>();
    c.urlList.add(new URL("http","www.google.com",8080,""));
    c.urlList.add(new URL("http","www.yahoo.com",8080,""));   

    Marshaller<Complex> m = TwoLattes.createMarshaller(Complex.class);
    Json.Object obj = m.marshall(c);
    System.out.println(obj);
    }
    catch(Exception ex)
    {
      System.out.println(ex.getMessage());
    }
  }
}

JSON:

What is the expected output? What do you see instead?
expected output:
{"urlList":["http://www.google.com:8080","http://www.yahoo.com:8080"]}

I see null, and the exception is mentioned below.

Please provide any additional information below.
I am having the following exception right now:
java.lang.ClassCastException

Original issue reported on code.google.com by nabil.sh...@gmail.com on 24 Dec 2009 at 5:11

GoogleCodeExporter commented 9 years ago
You'll want to do

TwoLattes.withType(URLType.class).createMarshaller(Complex.class);

to make this example work. This is the intended behaviour.

Original comment by pascallo...@gmail.com on 24 Dec 2009 at 6:10

GoogleCodeExporter commented 9 years ago
Issue 29 has been merged into this issue.

Original comment by pascallo...@gmail.com on 6 Jan 2010 at 7:46