Menu

#71 String containing special caracters can't be serialized

open
aalmiray
None
5
2008-08-21
2008-08-20
No

String that containing special caracters like "{", "(" or "[", can't be serialized or deserialized.

For example this test fails:
tJsonSource.put("weirdString", "[{}][:,;:.[][[]");
assertEquals("[{}][:,;:.[][[]", tJsonSource.get("weirdString"));

A JSONArray can't deserialized a String containing this kind of caracters, like JSONObject.
This is Ok
JSONObject jsonObject = JSONObject.fromObject( "{\"weirdString\":\"[{}][:,;:.[][[]\"}", tConfig);
This fails
jsonObject = JSONObject.fromObject( "{\"weirdStringArray\":[\"{912}\",\"[Hello]\",\"[]{}[,;.:[[]\"]}", tConfig);

Tha patch contains tests and corrections for the v 2.2.2 as I can't build the trunk (tests failures).

Discussion

  • aalmiray

    aalmiray - 2008-08-21

    Logged In: YES
    user_id=1192026
    Originator: NO

    Thanks Philippe, we'll review the patch and make the proper adjustments to the code.

    - Andres

     
  • aalmiray

    aalmiray - 2008-08-21
    • assigned_to: nobody --> aalmiray
     
  • philippe Kernevez

    Logged In: YES
    user_id=263696
    Originator: YES

    I have trouble for building with maven on windows.
    You may change the inner class JsonErrorDetector static.
    " public static class JsonErrorDetector implements JsonEventListener{" instead of " public class JsonErrorDetector implements JsonEventListener{"

     
  • philippe Kernevez

    New patch with both jdk13 and jdk15 modification

     
  • philippe Kernevez

    Logged In: YES
    user_id=263696
    Originator: YES

    File Added: patchJSONLibBis.txt

     
  • philippe Kernevez

    Logged In: YES
    user_id=263696
    Originator: YES

    I upload a new version of the patch.
    In the first one I didn't see the jdk15 source path, so only half of the code has been corrected.
    This patch has been testing with the ant build instead of the Maven build.
    I always have a groovy test that fails (even without my modofication). I suppose that the Groovy test can't but run with success on windows plateform.

    The failing test is : TestJsonSlurper.testParseUri()
    The reason is that it can't understand the root Url staring with "d:\" that is the drive where I install the project.

    The full stack is

    Testcase: testParseUri took 9,235 sec
    Caused an ERROR
    D
    java.net.UnknownHostException: D
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:177)
    at java.net.Socket.connect(Socket.java:520)
    at java.net.Socket.connect(Socket.java:470)
    at sun.net.NetworkClient.doConnect(NetworkClient.java:157)
    at sun.net.NetworkClient.openServer(NetworkClient.java:118)
    at sun.net.ftp.FtpClient.openServer(FtpClient.java:488)
    at sun.net.ftp.FtpClient.openServer(FtpClient.java:475)
    at sun.net.www.protocol.ftp.FtpURLConnection.connect(FtpURLConnection.java:270)
    at sun.net.www.protocol.ftp.FtpURLConnection.getInputStream(FtpURLConnection.java:352)
    at net.sf.json.groovy.JsonSlurper.parse(JsonSlurper.java:55)
    at net.sf.json.groovy.JsonSlurper.parse(JsonSlurper.java:63)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:230)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:912)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:946)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:756)
    at org.codehaus.groovy.runtime.InvokerHelper.invokePogoMethod(InvokerHelper.java:778)
    at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:758)
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptBytecodeAdapter.java:170)
    at net.sf.json.groovy.TestJsonSlurper.testParseUri(TestJsonSlurper.groovy:58)

    Do the Groovy test be successfull with windows ?

     
  • aalmiray

    aalmiray - 2008-08-22

    Logged In: YES
    user_id=1192026
    Originator: NO

    Philippe, seems like that testcase in particular is a bit brittle. We test on Linux so that is why we never encountered the error.
    And yes, the proper way to build the package is using Ant not Maven. I know, weird but is done this way because Maven can't replace a source class with the same name easily.

    - Andres

     
  • Dan F

    Dan F - 2010-05-24

    I think perhaps this bug hits me too. I'm having problems with a text field that has []s. Status?

     
  • Dan F

    Dan F - 2010-05-24

    Hmm, I should say I might have a different bug, not sure.

    This code:

    JSONObject obj = new JSONObject();
    obj.put("text", text);
    logger.info("obj.text: " + obj.get("text"));

    Fails: String text = "[0] [a]";
    Okay: String text = "[b] [a]";

    The failure logs:

    INFO: obj.text: [0]

    Version json-lib-2.3.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.