Coder Social home page Coder Social logo

json-io's Introduction

The official source code for json-io is now located at https://github.com/jdereg/json-io
 
The source code checked in here is older and will not be updated.  I plan to keep the available sources, jar, and javadoc updated here in the download section, for those who are not using Maven for builds.

json-io's People

Contributors

jdereg avatar

Watchers

 avatar

json-io's Issues

Float NaN value causes token exception (expects null)

What steps will reproduce the problem?
1. Make a simple object with a float member and a NaN value
2. Make a JSON String from the object
3. Try to make an object from the JSON String

What is the expected output? What do you see instead?
Object with original values. Exception null token expected.

What version of the product are you using? On what operating system?
GIT Trunk 3835d21aa371fd24e092f10e6deeccb1c75efe49

Please provide any additional information below.
Not needed.

Original issue reported on code.google.com by [email protected] on 20 May 2015 at 8:02

Import library?

What steps will reproduce the problem?
1. Copy .jar file to root folder
2. JsonWriter symbol could not be resolved

What is the expected output? What do you see instead?

Symbol should be resolved.

What version of the product are you using? On what operating system?

Symbol should be resolved.

Please provide any additional information below.

I am relatively new to Java so this may be as simple as somehow pointing to the 
.jar file. I am using IntelliJ IDE and this is a Maven project.

Original issue reported on code.google.com by [email protected] on 16 Mar 2013 at 7:29

In Java 7, the Throwable type contains java.util.Collections$UnmodifiableRandomAccessList, which does not allow a null constructor arg

What steps will reproduce the problem?

String json = JsonWriter.objectToJson(new Exception("whatever"));
JsonReader.jsonToJava(json);

What is the expected output? What do you see instead?

Expected output is an instance of the exception. The actual output is 
java.io.IOException: Could not instantiate 
java.util.Collections$UnmodifiableRandomAccessList using any constructor

What version of the product are you using? On what operating system?

version 2.2.30 on windows 7, 64 bit.

Please provide any additional information below.

This only seems to be an issue when moving to Java 7 (i've only tried update 40 
so far, which is the latest).

The issue is that the Throwable type has a SUPPRESSED_SENTINEL field of type 
java.util.Collections$UnmodifiableRandomAccessList, which only accepts a non 
null argument in its constructor. However, when JsonReader tries to create an 
instance and there's no default constructor, it attempts to pass in null 
arguments for non primitive constructor arguments. One solution would be to 
attempt both null and non null constructor arguments. These non null arguments 
would be replaced by the field setting reflection logic after the instance is 
created, so they shouldn't gunk up the object.

Original issue reported on code.google.com by [email protected] on 23 Sep 2013 at 5:49

Abbreviation for package path

What steps will reproduce the problem?
Serialize objects with long package names.

What is the expected output? What do you see instead?
{"@type":"package.is.very.long.and.clutters.result.file.to.my.Foo","property"

What version of the product are you using? On what operating system?
2.0.1

Please provide any additional information below.
Hi,

I'm playing around with your json lib, and thought is the following is possible:
When I look at serializations, I can see that the full @type path is defined 
for every object, like the statement above.

Wouldn't it be better to save some kind of abbreviation for every object type, 
and reuse it again. Cause full qualified package names can get quite long, 
which will result in many redundant entries for serialized content.
For my case the filesize could probably be reduced by over 50% if kind of 
shortcuts to the objects would be used.

Original issue reported on code.google.com by [email protected] on 15 Feb 2013 at 3:58

Back reference (###) does not match any object id in input, field

When trying to de-serialize from JSON to Object using the the JSONReader I am 
getting the following errors:

Back reference (###) does not match any object id in input, field 'null'
Exception in thread "main" java.io.IOException: 85 unresolved references:
    Unresolved reference 1
        @ref ###
        field null

I am using the JsonWriter to produce the serialized version. 

The version is json_io-1.0.4 and system is
Java: 1.6.0_25; Java HotSpot(TM) 64-Bit Server VM 20.0-b11
System: Windows 7 version 6.1 running on amd64; Cp1252; en_US


The objects that I am attempting to serialize are very complex and the object 
graph is deep but the Refs that are being pointed to are ints and shorts. Their 
containers are also using generics(Not sure if that matters but I thought I 
would mention it).

Original issue reported on code.google.com by [email protected] on 26 Jan 2012 at 3:22

cloneObject(String s)

What steps will reproduce the problem?
1.
public Object cloneObject(Object root)
{
    return JsonReader.jsonToJava(JsonWriter.objectToJson(root));    
}
2. cloneObject("Hello.")
3.  Input is invalid JSON; does not start with '{' or '[', c=34

What is the expected output? What do you see instead?
"Hello."

What version of the product are you using? On what operating system?
2.4.5

Please provide any additional information below.


Original issue reported on code.google.com by [email protected] on 13 Feb 2014 at 10:50

Serializing Maps as Simple JSON Maps

What steps will reproduce the problem?
1. class TestClass {public JsonObject<String, String> x;}
2. serialize an instance of TestClass
3. try to deserialize it

What is the expected output? What do you see instead?
serialization works and produces a nice json string, but deserializing the same 
output produces a null x.

it looks like the JsonObject output doesn't produce a @type field, so it just 
returns null when it's injected into TestClass

What version of the product are you using? On what operating system?
2.0.1


Original issue reported on code.google.com by [email protected] on 2 Apr 2013 at 4:18

no built in support for enums

What steps will reproduce the problem?
1. run the attached java example

What is the expected output? What do you see instead?
when trying do deserialize enums types as part of a parent class - the returned 
result is null.  

What version of the product are you using? On what operating system?
latest

Please provide any additional information below.


Original issue reported on code.google.com by [email protected] on 22 Oct 2012 at 12:16

Attachments:

IllegalAccessException

What steps will reproduce the problem?
1. Introduce a final variable without a set method
2. Deserialize with jsonToObject version 2.28
3. Upgrade from 2.28 to 2.52

What is the expected output? What do you see instead?
Expected serialization/deserialization to still work as before, instead get an 
IllegalAccessException.


What version of the product are you using? On what operating system?
2.52 on Debian 7


Please provide any additional information below.
This USED to be the ONLY serializer that just worked out-of-the-box, very 
frustrating...


Original issue reported on code.google.com by [email protected] on 23 Apr 2014 at 8:42

JsonWriter not working as expected for single string input; works for other types

What steps will reproduce the problem?
1. conversion of String "123" to json using JsonWriter.objectToJson(str) 
returns "123"
2. so, conversion to a String object using JsonReader.jsonToJava("123") fails 
with:

java.io.IOException: Input is invalid JSON; does not start with '{' or '[', c=34
Last read: "

What is the expected output? What do you see instead?
I'm guessing that the writer is expected to output something along the lines:
{"@type":"string","value":"123"}.
This works, though returns an array, which isn't what I want:
["123"]
As does this:
{"@type":"string","value":["123"]}

What version of the product are you using? On what operating system?
Latest. Windows 8.

Please provide any additional information below.
JDK 6

Original issue reported on code.google.com by [email protected] on 4 Apr 2014 at 4:49

class cast exception

        String  jsonString = "{\"name\": \"mybank\",\"address\": \"mybank address\"}";

        InputStream inputStream = new ByteArrayInputStream(jsonString.getBytes());

        JsonReader jr = new JsonReader(inputStream);
        Bank bank = (Bank) jr.readObject();

        System.out.println(bank.getName());
----------------------------------------------------------
when i use this code i got class cast exception  as following 
Exception in thread "main" java.lang.ClassCastException: java.lang.Object 
cannot be cast to com.test.Bank
    at com.test.TestJson.main(TestJson.java:22)

please help me in this

thank you

Original issue reported on code.google.com by [email protected] on 5 Jul 2012 at 2:49

Access to JsonObject.target required in custom JsonClassReaders

I was not able to get a custom JsonClassReader for a non-primitive to work 
without accessing JsonObject.target. I always got unresolved references. In all 
built-in Readers the result is not just returned, but always also set to 
JsonObject.target. After doing this in my Reader it worked.

Do i miss something or is this an oversight?

Original issue reported on code.google.com by [email protected] on 4 Jul 2013 at 8:26

JsonWriter.objectToJson breaks on HashMap<Double, Double>

What steps will reproduce the problem?

public class Console {

    HashMap<Double, Double> hm = new HashMap<Double, Double>();

    public Console() {
        hm.put(345.0, 453.0);
    }

    public static void main(String arg[]) {
        Console c = new Console();

        String s;
        try {
            HashMap<String, Object> args = new HashMap<>();
            args.put(JsonWriter.PRETTY_PRINT, true);

            s = JsonWriter.objectToJson(c, args);

            System.out.println(s);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}

What is the expected output? What do you see instead?

json string is expected, insdead it gives exception:
Exception in thread "main" java.lang.ClassCastException: java.lang.Double 
cannot be cast to java.lang.String

What version of the product are you using? On what operating system?

2.7.1

Please provide any additional information below.

I guess it should be easy to fix, HashMap<Integer, Double> works fine...

Original issue reported on code.google.com by [email protected] on 1 Nov 2014 at 1:58

json for enum includes private fields, causes error when parsing

What steps will reproduce the problem?
1. I have an enum like:

public enum AssetType {
    ABSTRACT(AssetEncoding.CONTENT_ENCODING), 
    AUTOCOMPLETE(AssetEncoding.CONTENT_ENCODING),
    ...
    private EnumSet<AssetEncoding> encoding;
    private AssetType(EnumSet<AssetEncoding> encoding) { 
        this.encoding = encoding;
    }
    ...
}

2. The emitted JSON for this enum includes the "encoding" value as follows:
   "x" : {
        "@id": 1548,
        "@type": "com.uptodate.web.api.AssetType",
        "encoding": {
            "@id": 60,
            "@type": "java.util.RegularEnumSet",
            "@items": [
                {
                    "@type": "com.uptodate.web.api.AssetEncoding",
                    "name": "COMPRESSED",
                    "ordinal": 0
                },
                {
                    "@type": "com.uptodate.web.api.AssetEncoding",
                    "name": "ENCRYPTED",
                    "ordinal": 1
                },
                {
                    "@type": "com.uptodate.web.api.AssetEncoding",
                    "name": "BASE64",
                    "ordinal": 2
                },
                {
                    "@type": "com.uptodate.web.api.AssetEncoding",
                    "name": "JSON",
                    "ordinal": 3
                }
            ]
        },
        "name": "TOPIC",
        "ordinal": 10
    },

3. This causes the following exception
    java.lang.ClassCastException: class com.uptodate.web.api.AssetEncoding != null
    at java.util.EnumSet.typeCheck(Unknown Source)
    at java.util.RegularEnumSet.add(Unknown Source)
    at java.util.RegularEnumSet.add(Unknown Source)
    at com.cedarsoftware.util.io.JsonReader.traverseCollection(JsonReader.java:1587)
    at com.cedarsoftware.util.io.JsonReader.convertMapsToObjects(JsonReader.java:1286)
    at com.cedarsoftware.util.io.JsonReader.traverseCollection(JsonReader.java:1585)
    at com.cedarsoftware.util.io.JsonReader.convertMapsToObjects(JsonReader.java:1286)
    at com.cedarsoftware.util.io.JsonReader.traverseCollection(JsonReader.java:1585)
    at com.cedarsoftware.util.io.JsonReader.convertMapsToObjects(JsonReader.java:1286)
    at com.cedarsoftware.util.io.JsonReader.convertParsedMapsToJava(JsonReader.java:1233)
    at com.cedarsoftware.util.io.JsonReader.readObject(JsonReader.java:1193)
    at com.cedarsoftware.util.io.JsonReader.jsonToJava(JsonReader.java:1085)



What is the expected output? What do you see instead?

I am surprised to see the emitted JSON contain the enum's "ordinal" value and 
the enum's private fields.  I would expect to see just the name:

   "x" : {
        "@id": 1548,
        "@type": "com.uptodate.web.api.AssetType",
        "name": "TOPIC",
    },

In fact, other JSON serializers (GSON for example) emits just the name:

   "x" : "TOPIC"



What version of the product are you using? On what operating system?

2.7.0 on Linux

Please provide any additional information below.

I can work around the problem by declaring my enum fields "transient".  That 
would not work for third-party software obviously, so I think the tool would be 
better if it handled this situation properly.

That's it.  I've had no other problems, it is a great library!  Thank you.




Original issue reported on code.google.com by [email protected] on 2 Sep 2014 at 10:01

Serializing breaks for java.util.Date subclasses

What steps will reproduce the problem?
1. Serialize and deserialize a java.sql.Date, java.sql.Time, or 
java.sql.Timestamp
2. (e.g.) 
JsonReader.toJava("{\"@type\":\"java.sql.Date\",\"value\":1372136400000}") will 
return a java.util.Date rather than a java.sql.Date

What is the expected output? What do you see instead?
An instance of the respective java.sql.Date, java.sql.Time, or 
java.sql.Timestamp; instead you get a java.util.Date

What version of the product are you using? On what operating system?
2.0.1, Windows 7

Please provide any additional information below.

Since there is a specific reader/writer for java.util.Date, it handles the 
three subclass types as well but loses type specificity in the process.  A 
workaround is to provide custom readers/writers for the subclasses (these are 
highly redundant to the already existent java.util.Date reader/writer, however).

Original issue reported on code.google.com by [email protected] on 13 Sep 2013 at 8:51

Feature request: Totally disable '@type' field

I wanted to use json-io for serializing my data to JSON for my web client 
without the intention of ever deserializing it. However about the half of my 
data are these type fields, which I don't use at all, so it is just overhead 
for me.

It would be nice if there were an option to totally disable them.

Original issue reported on code.google.com by [email protected] on 6 Nov 2014 at 11:34

java.io.IOException: Class instance 'Foo' could not be created at position 10533

I've been using json-io with great success to clone Java objects.  I used to 
use this format:
    JsonReader.toJava(JsonWriter.toJson(root));.  
Now, I've begun using the documented technique with the latest jar:
    JsonReader.jsonToJava(JsonWriter.objectToJson(root));.  
Looking at the code they both should operate the same.

Recently though, I've been getting random errors on the Foo class I've been 
cloning (see the summary/title of this issue). This error never occurred 
before.  The exception continues each time I run the app until I have Android 
remove (kill?) the app from the list of recent apps... or reinstall the app.

What would cause a random issue like this?  How do I correct it?  Is it related 
to the method used to clone?



What steps will reproduce the problem?
See above.

What is the expected output? What do you see instead?
See above.

What version of the product are you using? On what operating system?
json-io-2.0.1.jar
Android 4.2.2

Please provide any additional information below.

Original issue reported on code.google.com by [email protected] on 9 Jun 2013 at 8:12

loadClass(name) raises ClassNotFound Exception although Class exists / solution available

What steps will reproduce the problem?
1. Using JsonReader.jsonToJava(String message) in a "MessageTextEncoder"-Class 
inside Method "public Message decode(String string) throws DecodeException" for 
a WebLogic Server (e.g. WildFly). See 
http://docs.oracle.com/middleware/1213/wls/WLPRG/websockets.htm.

What is the expected output? What do you see instead?
* The expected output should be the created Object out of the JSON Text.
* Instead a "error" cause of a "ClassNotFound"-Exception is raised: 
23:28:23,638 ERROR [stderr] (default I/O-3)     at 
com.cedarsoftware.util.io.JsonReader.error(JsonReader.java:3240)
23:28:23,639 ERROR [stderr] (default I/O-3)     at 
com.cedarsoftware.util.io.JsonReader.classForName(JsonReader.java:2975)
23:28:23,639 ERROR [stderr] (default I/O-3)     at 
com.cedarsoftware.util.io.JsonReader.createJavaObjectInstance(JsonReader.java:21
04)
23:28:23,639 ERROR [stderr] (default I/O-3)     at 
com.cedarsoftware.util.io.JsonReader.convertParsedMapsToJava(JsonReader.java:123
2)
23:28:23,639 ERROR [stderr] (default I/O-3)     at 
com.cedarsoftware.util.io.JsonReader.readObject(JsonReader.java:1193)
23:28:23,639 ERROR [stderr] (default I/O-3)     at 
com.cedarsoftware.util.io.JsonReader.jsonToJava(JsonReader.java:1085)

* Solution would be:
Please change JsonReader.java:3022
From: currentClass = 
Thread.currentThread().getContextClassLoader().loadClass(className);
To: currentClass = Class.forName( className );

What version of the product are you using? On what operating system?
Version: json-io: 2.7.0
OS: OS X 10.9.4
Java: JavaSE-1.8

Please provide any additional information below.
* Solution would be:
Please change JsonReader.java:3022
From: currentClass = 
Thread.currentThread().getContextClassLoader().loadClass(className);
To: currentClass = Class.forName( className );

Original issue reported on code.google.com by [email protected] on 21 Aug 2014 at 10:11

Attachments:

Double.NaN not handled correctly.

What steps will reproduce the problem?
1. Serialize somthing containing a NaN Double Value
2. Deserialize it

Exception in thread "main" java.io.IOException: Expected token: null
Last read: 
Peptide","ordinal":2},"targetCategory":{"@id":14,"name":"Tissue","ordinal":1},"a
ffinity":{"fromV":Na

What is the expected output? What do you see instead?
The NaN may has to be put into ""?

What version of the product are you using? On what operating system?
2.7.2

Please provide any additional information below.


Original issue reported on code.google.com by [email protected] on 10 Nov 2014 at 4:45

maybe unnecessary call of convertParsedMapsToJava inside JsonReader.readObject()

What version of the product are you using? On what operating system?
2.6.1, Suse Linux

Please provide any additional information below.

if I don't want to have the java object, but only the map representation of the 
json (by giving the constructor 'true' for noObjects), convertParsedMapsToJava 
is still invoked - is this necessary or simply an unnecessary overhead in this 
case? This is the readObject() code from JsonReader:

    public Object readObject() throws IOException
    {
        Object o = readJsonObject();
        if (o == EMPTY_OBJECT)
        {
            return new JsonObject();
        }

        Object graph = convertParsedMapsToJava((JsonObject) o);

        // Allow a complete 'Map' return (Javascript style)
        if (_noObjects)
        {
            return o;
        }
        return graph;
    }

Maybe it could be more efficient if convertParsedMapsToJava is only invoked if 
necessary:

    public Object readObject() throws IOException
    {
        Object o = readJsonObject();
        if (o == EMPTY_OBJECT)
        {
            return new JsonObject();
        }

        // Allow a complete 'Map' return (Javascript style)
        if (_noObjects)
        {
            return o;
        }

        Object graph = convertParsedMapsToJava((JsonObject) o);

        return graph;
    }


Original issue reported on code.google.com by [email protected] on 8 Jul 2014 at 1:04

Feature request: add a optional fallback type parameter for the toplevel json container to JsonReader.jsonToJava(json);

We give the possibility to specify http get parameters also as json strings, to 
allow class objects as parameter types for the web interfaces also.

The problem is, by using json-io, specifying @type in the json string is 
mandatory for deserialization, right? Thus, the users have to specify it, which 
is not so nice (for the return values its fine of course, but for parameters?)

I love the way json-io deals with types, for me, it is the best solution to 
support polymorphism I have seen in such a library. Nevertheless, in this case, 
the underlying type of the parameter normally not changes - it should be 
transparent for the (e.g. javascript) user of the interface who creates the 
json, and clear for the server.

Is it possible to add another method to JsonReader.jsonToJava(String json, 
Class toplevelFallbackType) - where toplevelFallbackType could be also String, 
Type, etc. of course.
This parameter would then be used as fallback if the @type was not specified in 
the toplevel json object.
I know this would not work with polymorphism, but it would help us a lot and 
would be maybe a nice enhanchement of json-ios functionality:)

Thanks and best regards

Christian

Original issue reported on code.google.com by [email protected] on 8 Jul 2014 at 3:44

serializing an empty ArrayList produces {} instead of []

What steps will reproduce the problem?
1. class X {ArrayList<String> list = new ArrayList<String>();}
2. X x = new X();
3. System.out.println(JsonWriter.toJson(x));

What is the expected output? What do you see instead?
Should produce: {"@type":"X","list":[],"this$0":{}}
But instead, it produces
{"@type":"X","list":{},"this$0":{}}

Note the curly braces for "list".  That signifies an empty object rather than 
an empty array.

Note also that if we do add an element to list:
    x.list.add("test");

We get:
{"@type":"vericle.server.ticket.FetchTicketsActionHandlerTest$X","list":["test"]
,"this$0":{}}

which signifies that list is really an array, not a regular object.


What version of the product are you using? On what operating system?
2.0.1 on linux


Original issue reported on code.google.com by [email protected] on 5 Apr 2013 at 9:55

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.