Migrate from GitHub to SourceForge with this tool. Check out all of SourceForge's recent improvements.

#6 empty string,and number handling


version: 2.0b4
handling empty string values like
and number parsing.

+ this patch contains corrections to the tests.


  • Hrotkó Gábor

    Hrotkó Gábor - 2010-05-20

    empty string,and number handling

  • Charlie Hubbard

    Charlie Hubbard - 2010-05-20

    Can you explain what problem this patch fixes in more detail? Can you give the input, the expected output, and the actual output?

  • Hrotkó Gábor

    Hrotkó Gábor - 2010-05-20

    I have a json like this:

    String jsonString = "{\"prop1\":\"\",\"prop2\":\"null\",\"myInt\":\"0\"}";

    A class like this:

    protected String prop1;
    protected Long prop2;
    protected Integer myInt;
    public void setMyInt(Integer myInt) {
    this.myInt = myInt;
    public void setProp2(Long prop2) {
    this.prop2 = prop2;
    public void setProp1(String prop1) {
    this.prop1 = prop1;

    When I try to deserialize:

    MyClass mc = new JSONDeserializer<MyClass>().use( null, MyClass.class ).deserialize(jsonString);

    I got various exceptions, like:

    java.lang.IllegalArgumentException: argument type mismatch
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at flexjson.ObjectBinder.bindObject(ObjectBinder.java:300)
    at flexjson.ObjectBinder.bindObject(ObjectBinder.java:152)
    at flexjson.ObjectBinder.bind(ObjectBinder.java:125)
    at flexjson.JSONDeserializer.deserialize(JSONDeserializer.java:121)

    flexjson.JSONException: [ prop1 ]: Can not convert java.lang.String into java.lang.Class
    at flexjson.ObjectBinder.cannotConvertValueToTargetType(ObjectBinder.java:174)
    at flexjson.factories.IntegerObjectFactory.instantiate(IntegerObjectFactory.java:13)
    at flexjson.ObjectBinder.bind(ObjectBinder.java:90)
    at flexjson.ObjectBinder.bindIntoObject(ObjectBinder.java:143)
    at flexjson.factories.ClassLocatorObjectFactory.instantiate(ClassLocatorObjectFactory.java:38)
    at flexjson.ObjectBinder.bind(ObjectBinder.java:90)
    at flexjson.ObjectBinder.bind(ObjectBinder.java:69)
    at flexjson.JSONDeserializer.deserialize(JSONDeserializer.java:150)

    but with this patch, it got converted successfully.

  • Charlie Hubbard

    Charlie Hubbard - 2010-05-20

    Thank you for the clarification and the patch! I will look it over.

  • Comment has been marked as spam. 

    You can see all pending comments posted by this user  here


    Anonymous - 2010-10-14

    the NumberFactory patch is nice

    i believe it make sense to convert String to number, this is quite useful for deserialization

  • Charlie Hubbard

    Charlie Hubbard - 2010-10-15

    Ok this patch has been applied. The fixes will be included in the next release which is 2.1.

  • Charlie Hubbard

    Charlie Hubbard - 2010-10-15
    • status: open --> closed-fixed
  • Charlie Hubbard

    Charlie Hubbard - 2010-10-15
    • assigned_to: nobody --> charliehubbard

Log in to post a comment.