Inconsistent behavior between Java and Android -


i'm using shared library in both android , java , have found inconsistency on behavior.

the library depends on org.json.jsonobject. in jar contained on library itself, seems somehow android overrides jar own implementation of json.

when do:

    double = 0.1;     jsonobject b = new jsonobject();     b.put("hola", a);     flocksonversionstring = b.getstring("hola"); 

in android, runs no problems, in java, throws exception because 0.1 not string. second behavior 1 expected beginning.

when do

    object aobj = b.get("hola");     if(aobj instanceof float){         system.out.println("hola float");     } else if (aobj instanceof long){         system.out.println("hola long");     } else if (aobj instanceof double){         system.out.println("hola double");     } else if (aobj instanceof string){         system.out.println("hola string");     } else {         system.out.println("hola has unknown type");     } 

both in android , java hola double.

the curious thing that, if go source code of org.json.jsonobject getstring() method declared follows:

public string getstring(string key) throws jsonexception {     object object = get(key);     if (object instanceof string) {         return (string)object;     }     throw new jsonexception("jsonobject[" + quote(key) +         "] not string."); } 

which seems totally expected behavior because it's checking if object string , throwing exception if isn't.

any idea why happening?

thank you!

(i can't change dependency on org.json.jsonobject since break compatibility between android , java )

are sure using same jar in both projects?

android's org.json.jsonobject.tostring(string) different:

/**  * returns value mapped {@code name} if exists, coercing if  * necessary, or throws if no such mapping exists.  *  * @throws jsonexception if no such mapping exists.  */ public string getstring(string name) throws jsonexception {     object object = get(name);     string result = json.tostring(object);     if (result == null) {         throw json.typemismatch(name, object, "string");     }     return result; } 

json.tostring(object):

static string tostring(object value) {     if (value instanceof string) {         return (string) value;     } else if (value != null) {         return string.valueof(value);     }     return null; } 

in case not throw exception on android.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -