A recent issue in our app came up where user submitted string value 'null'
is being stored into the data base as '"null"'. Basically double quotes are
being added at the start and end of the String.
Investigation revealed that JSON-lib doesn't seem to handle the 'null'
string value correctly. This is exhibited by the following test methods.
@Test
public void shouldHandleNullStringInJsonFormattedString() {
String jsonTest = "[\"null\",\"aValue\"]";
assertTrue(jsonTest.contains("\"null\""));
assertFalse(jsonTest.contains("\"\\\"null\\\"\""));
String convertedBack = JSONSerializer.toJSON(jsonTest).toString();
assertFalse(convertedBack.contains("\"\\\"null\\\"\""));
}
@Test
public void shouldHandleNullStringLiteral() {
JSONArray jsonArray1 = JSONArray.fromObject(Arrays.asList(null,"b"));
JSONArray jsonArray2 =
JSONArray.fromObject(Arrays.asList(JSONNull.getInstance(),"b"));
JSONArray jsonArray3 = JSONArray.fromObject(Arrays.asList("null","b"));
assertEquals("[null,\"b\"]", jsonArray1.toString());
assertEquals("[null,\"b\"]", jsonArray2.toString());
assertEquals("[\"null\",\"b\"]", jsonArray3.toString());
}
basically when browser sends ["null", "aValue"] to server, JSON-lib changes
it to ["\"null\"", "aValue"].
Also from the server side we are unable to construct a JSON formatted
String like ["null", "b"] using JSONArray. JSON-lib does not seem to
handle these two basic scenarios properly.
JSONUtils.mayBeJSON method treats 'null' string as a possible JSON value.
Is this correct ? The issue seems to stem from this logic

All,
I have the following XML snippet:
<article>
<section>
<headline><![CDATA[Test Headline.]]></headline>
</section>
</article>
And when I run it through the following transform:
XMLSerializer xmlToJsonSerializer = new XMLSerializer();
xmlToJsonSerializer.setRemoveNamespacePrefixFromElements(true);
xmlToJsonSerializer.setNamespaceLenient(true);
xmlToJsonSerializer.setTypeHintsCompatibility(false);
JSON json = (JSON) xmlToJsonSerializer.read(xmlString);
String stringJson = json.toString(4);
I get:
[["Test Headline."]]
But if I have the following:
<?xml version="1.0" encoding="UTF-16"?>
<article>
<section>
<headline><![CDATA[Test Headling.]]></headline>
<subheadline><![CDATA[Test Headling.]]></subheadline>
</section>
</article>
It works correctly as such:
[{
"headline": "Test Headling.",
"subheadline": "Test Headling."
}]
Thanks,
Ron
The information contained in this e-mail is confidential and/or
proprietary to Capital One and/or its affiliates. The information
transmitted herewith is intended only for use by the individual
or entity to which it is addressed. If the reader of this
message is not the intended recipient, you are hereby notified
that any review, retransmission, dissemination, distribution,
copying or other use of, or taking of any action in reliance upon
this information is strictly prohibited. If you have received
this communication in error, please contact the sender and delete
the material from your computer.

HI,
I have run into exactly this problem.
probably using org.apache.commons.lang.math.NumberUtils#createNumber
is not the best idea, since it is not exactly written for JSON.
i am not happy with using json like {"a":2312.4756237845354d}
since this ist not a valid json.
is anyone going to solve this problem?
are there any supposed solutions?
greetings
Peter

OK - I finally solved the problem.
1. In my test application I was declaring Server as a static nested
class. json-lib seemed OK with this as I was invoking directly from
main(). However, when I converted Server to a non-static class and
invoked it from an instance of my application class, then I got the
same error message as I was getting in my legacy application.
2. I moved Server out of the test application file so that it was no
longer nested, and then it worked correctly again.
3. I moved Server out of my legacy application file so that it was no
longer nested, an now it works as expected.
Is there some general reason for this behavior? Is it generally not OK
to try serializing and deserializing nested classes? Is there some
reason nested classes are OK if they are declared static and called from
main()?
Anyway - this seems like pretty weird behavior - and the diagnostics
were not really helpful.
Cheers, Eric
On 2012-03-09 2:00 PM, Eric Kolotyluk wrote:
> The relevant source is all in the same file - so there should not be a
> classpath issue there.
>
> I have checked the classpath and have moved all the relevant jars to
> the beginning:
>
> json-lib-2.4-jdk15.jar
> commons-beanutils-1.8.0.jar
> commons-collections-3.2.1.jar
> commons-lang-2.5.jar
> ezmorph-1.0.6.jar
>
> Still I get the same error. From within Eclipse, I can see that I am
> calling json-lib-2.4-jdk15.jar and these are exactly the same
> libraries used in my stand-alone program that works. Sadly while my
> stand-alone project uses Maven, the legacy project does not, but I
> have checked several times now and everything should be kosher.
>
> Any other suggestions?
>
> I am tempted to try to use |NewBeanInstanceStrategy| as mentioned in
> http://json-lib.sourceforge.net/advanced.html but neither the
> documentation nor the javadoc has any clarity on what this means. An
> example somewhere would be nice.
>
> Cheers, Eric
>
> On 2012-03-09 1:37 PM, Tim Harsch wrote:
>> Sounds suspiciously like you might be picking an incorrect version of
>> your source off the classpath. It is a common technique when you see
>> this to pull out the code into a stand alone app as you have done.
>> If that test is telling you that it works then you are either picking
>> up a wrong version of JSON lib, or an older compile of your source.
>> You probably just need to closely inspect your classpath is my guess.
>>
>> ------------------------------------------------------------------------
>> *From:* Eric Kolotyluk <eric.kolotyluk@...>
>> *To:* json-lib-user@...
>> *Sent:* Friday, March 9, 2012 1:09 PM
>> *Subject:* [json-lib-user] java.lang.NoSuchMethodException
>>
>> When I run the following code
>>
>> Server [] servers = (Server[])
>> JSONArray.toArray(jsonArray, Server.class); // line 1308
>>
>> I get
>>
>> net.sf.json.JSONException: java.lang.NoSuchMethodException:
>> com.kodak.vip.sct.view.PreferencesDialog$ServerPanel$Server.<init>()
>> at net.sf.json.JSONObject.toBean(JSONObject.java:288)
>> at net.sf.json.JSONArray.toArray(JSONArray.java:318)
>> at net.sf.json.JSONArray.toArray(JSONArray.java:250)
>> at
>> com.kodak.vip.sct.view.PreferencesDialog$ServerPanel$ServerComboBox.<init>(PreferencesDialog.java:1308)
>>
>> So far as I can tell, json-lib thinks it cannot find the no-arg
>> constructor for my Server class. But it is there, I can see it.
>>
>> I have even tested this same line of code in a stand-alone test
>> application and it works fine, but when I am using it in my real
>> application I get this exception.
>>
>> What could be causing json-lib to be confused?
>>
>> Cheers, Eric
>>
>> ------------------------------------------------------------------------------
>> Virtualization & Cloud Management Using Capacity Planning
>> Cloud computing makes use of virtualization - but cloud computing
>> also focuses on allowing computing to be delivered as a service.
>> http://www.accelacomm.com/jaw/sfnl/114/51521223/
>> _______________________________________________
>> json-lib-user mailing list
>> json-lib-user@...
>> <mailto:json-lib-user@...>
>> https://lists.sourceforge.net/lists/listinfo/json-lib-user
>>
>>

The relevant source is all in the same file - so there should not be a
classpath issue there.
I have checked the classpath and have moved all the relevant jars to the
beginning:
json-lib-2.4-jdk15.jar
commons-beanutils-1.8.0.jar
commons-collections-3.2.1.jar
commons-lang-2.5.jar
ezmorph-1.0.6.jar
Still I get the same error. From within Eclipse, I can see that I am
calling json-lib-2.4-jdk15.jar and these are exactly the same libraries
used in my stand-alone program that works. Sadly while my stand-alone
project uses Maven, the legacy project does not, but I have checked
several times now and everything should be kosher.
Any other suggestions?
I am tempted to try to use |NewBeanInstanceStrategy| as mentioned in
http://json-lib.sourceforge.net/advanced.html but neither the
documentation nor the javadoc has any clarity on what this means. An
example somewhere would be nice.
Cheers, Eric
On 2012-03-09 1:37 PM, Tim Harsch wrote:
> Sounds suspiciously like you might be picking an incorrect version of
> your source off the classpath. It is a common technique when you see
> this to pull out the code into a stand alone app as you have done. If
> that test is telling you that it works then you are either picking up
> a wrong version of JSON lib, or an older compile of your source. You
> probably just need to closely inspect your classpath is my guess.
>
> ------------------------------------------------------------------------
> *From:* Eric Kolotyluk <eric.kolotyluk@...>
> *To:* json-lib-user@...
> *Sent:* Friday, March 9, 2012 1:09 PM
> *Subject:* [json-lib-user] java.lang.NoSuchMethodException
>
> When I run the following code
>
> Server [] servers = (Server[])
> JSONArray.toArray(jsonArray, Server.class); // line 1308
>
> I get
>
> net.sf.json.JSONException: java.lang.NoSuchMethodException:
> com.kodak.vip.sct.view.PreferencesDialog$ServerPanel$Server.<init>()
> at net.sf.json.JSONObject.toBean(JSONObject.java:288)
> at net.sf.json.JSONArray.toArray(JSONArray.java:318)
> at net.sf.json.JSONArray.toArray(JSONArray.java:250)
> at
> com.kodak.vip.sct.view.PreferencesDialog$ServerPanel$ServerComboBox.<init>(PreferencesDialog.java:1308)
>
> So far as I can tell, json-lib thinks it cannot find the no-arg
> constructor for my Server class. But it is there, I can see it.
>
> I have even tested this same line of code in a stand-alone test
> application and it works fine, but when I am using it in my real
> application I get this exception.
>
> What could be causing json-lib to be confused?
>
> Cheers, Eric
>
> ------------------------------------------------------------------------------
> Virtualization & Cloud Management Using Capacity Planning
> Cloud computing makes use of virtualization - but cloud computing
> also focuses on allowing computing to be delivered as a service.
> http://www.accelacomm.com/jaw/sfnl/114/51521223/
> _______________________________________________
> json-lib-user mailing list
> json-lib-user@...
> <mailto:json-lib-user@...>
> https://lists.sourceforge.net/lists/listinfo/json-lib-user
>
>

Sounds suspiciously like you might be picking an incorrect version of your source off the classpath. It is a common technique when you see this to pull out the code into a stand alone app as you have done. If that test is telling you that it works then you are either picking up a wrong version of JSON lib, or an older compile of your source. You probably just need to closely inspect your classpath is my guess.
>________________________________
> From: Eric Kolotyluk <eric.kolotyluk@...>
>To: json-lib-user@...
>Sent: Friday, March 9, 2012 1:09 PM
>Subject: [json-lib-user] java.lang.NoSuchMethodException
>
>When I run the following code
>
> Server [] servers = (Server[])
>JSONArray.toArray(jsonArray, Server.class); // line 1308
>
>I get
>
>net.sf.json.JSONException: java.lang.NoSuchMethodException:
>com.kodak.vip.sct.view.PreferencesDialog$ServerPanel$Server.<init>()
> at net.sf.json.JSONObject.toBean(JSONObject.java:288)
> at net.sf.json.JSONArray.toArray(JSONArray.java:318)
> at net.sf.json.JSONArray.toArray(JSONArray.java:250)
> at
>com.kodak.vip.sct.view.PreferencesDialog$ServerPanel$ServerComboBox.<init>(PreferencesDialog.java:1308)
>
>So far as I can tell, json-lib thinks it cannot find the no-arg
>constructor for my Server class. But it is there, I can see it.
>
>I have even tested this same line of code in a stand-alone test
>application and it works fine, but when I am using it in my real
>application I get this exception.
>
>What could be causing json-lib to be confused?
>
>Cheers, Eric
>
>------------------------------------------------------------------------------
>Virtualization & Cloud Management Using Capacity Planning
>Cloud computing makes use of virtualization - but cloud computing
>also focuses on allowing computing to be delivered as a service.
>http://www.accelacomm.com/jaw/sfnl/114/51521223/
>_______________________________________________
>json-lib-user mailing list
>json-lib-user@...
>https://lists.sourceforge.net/lists/listinfo/json-lib-user
>
>
>

When I run the following code
Server [] servers = (Server[])
JSONArray.toArray(jsonArray, Server.class); // line 1308
I get
net.sf.json.JSONException: java.lang.NoSuchMethodException:
com.kodak.vip.sct.view.PreferencesDialog$ServerPanel$Server.<init>()
at net.sf.json.JSONObject.toBean(JSONObject.java:288)
at net.sf.json.JSONArray.toArray(JSONArray.java:318)
at net.sf.json.JSONArray.toArray(JSONArray.java:250)
at
com.kodak.vip.sct.view.PreferencesDialog$ServerPanel$ServerComboBox.<init>(PreferencesDialog.java:1308)
So far as I can tell, json-lib thinks it cannot find the no-arg
constructor for my Server class. But it is there, I can see it.
I have even tested this same line of code in a stand-alone test
application and it works fine, but when I am using it in my real
application I get this exception.
What could be causing json-lib to be confused?
Cheers, Eric

While we are at it, it would be great if you could also support BadgerFish
(in particular, the possibility to NOT loose the name of elements of a list:
<myList>
<myElement>xxx</myElement>
<myElement>yyy</myElement>
</myList>
=> should return myList:{myElement:[xxx,yyy]}
If you can have this, I'm your first fan ;-)
Thanks (and I understand it's complicated to do everything ;-)
Olivier
On Tue, Nov 22, 2011 at 4:14 PM, Alan Hicks <al.hicks@...> wrote:
> I must look at committing a patch with an optional value to turn on/off
> sorting. At the time we had some deadlines that meant I could not do this
> and then got caught up with other items.
>
>
>
> On Tuesday, November 22, 2011, Olivier Chirouze <
> olivier.chirouze+jsonlib@...> wrote:
> > Funny :-) Thanks for sharing the feedback.
> > That proves how useful this line is! I don't really like that solution
> though...
> > In the meantime, I implemented a solution with more lines of code but
> that seems to get all I need:
> > - a xml2json.xsl stylesheet for XML => JSON (advantage: can use
> "BadgerFish" convention)
> > - jettison for JSON => XML (but quite complicated to implement)
> > So, in a word I did without JSON-lib but what a shame!
> > Olivier
> > On Tue, Nov 22, 2011 at 3:54 PM, Alan Hicks <al.hicks@...> wrote:
> >
> > We are using this library to convert from JSON to XML and XML to JSON.
> To get around the sorting issue we just commented out the call to
> "Arrays.sort( names );" in the Serializer. We have been using it like this
> since April 2010 with no issues.
> >
> > On Tuesday, November 22, 2011, Olivier Chirouze <
> olivier.chirouze+jsonlib@...> wrote:
> >> I though the "reply-all" was set to reply to
> json-lib-user@...! :-)
> >> Thanks for your reply anyway. Hope someone can react since I could not
> play with bug reports on Sourceforge!
> >> Olivier
> >>
> >> On Tue, Nov 22, 2011 at 3:25 PM, Morgan Packard <
> morgan@...> wrote:
> >>>
> >>> I'm afraid I'm just a dumb user of this project, I'm not involved in
> authoring or maintaining it in any way, so i'm not the right guy to ask
> about line 942.
> >>> -Morgan
> >>>
> >>> On Tue, Nov 22, 2011 at 3:52 AM, Olivier Chirouze <
> olivier.chirouze+jsonlib@...> wrote:
> >>>>
> >>>> Ok, I found what I see as a very strange... bug?
> >>>> Line 942 of XMLSerializer.java, in method processJSONObject(), I
> found...
> >>>> Arrays.sort( names );
> >>>> Why is it there for? I don't see the point in sorting elements,
> especially if the output is to be an XML. To me this line is 100% useless.
> >>>> I found existing bug entries on sourceforge and will try to push the
> resolution of these.
> >>>> Olivier
> >>>>
> >>>> On Tue, Nov 22, 2011 at 9:11 AM, Olivier Chirouze <
> olivier.chirouze+jsonlib@...> wrote:
> >>>>>
> >>>>> I agree with you.
> >>>>> But XML elements ARE ordered, right?
> >>>>> So, when one passes a list of JSON objects in a specific order, why
> change that order when converting to XML???
> >>>>>
> >>>>> On Mon, Nov 21, 2011 at 5:49 PM, Morgan Packard <
> morgan@...> wrote:
> >>>>>>
> >>>>>> I was under the impression that json dictionaries are unordered
> according to the spec.
> >>>>>> from json.org:
> >>>>>>
> >>>>>> JSON is built on two structures:
> >>>>>>
> >>>>>> A collection of name/value pairs. In various languages, this is
> realized as an object, record, struct, dictionary, hash table, keyed list,
> or associative array.
> >>>>>> An ordered list of values. In most languages, this is realized as
> an array, vector, list, or sequence.
> >>>>>>
> >>>>>> On Mon, Nov 21, 2011 at 11:45 AM, Olivier Chirouze <
> olivier.chirouze+jsonlib@...> wrote:
> >>>>>>>
> >>>>>>> Hi there,
> >>>>>>> I am playing with JSON lib conversion from JSON to XML and the
> opposite.
> >>>>>>> I am now facing a strange issue: converting from json string to
> XML seems to loose the order of elements in the process.
> >>>>>>> However in debug I can make sure the "insertOrder" property of my
> JSONObject is right! But xmlSerializer.write(myJSONObject) returns an XML
> string where child elements have been mixed up (seems to be exactly the
> opposite order!!...)
> >>>>>>> What should I do?
> >>>>>>> Thanks
> >>>>>>>
> ------------------------------------------------------------------------------
> >>>>>>> All the data continuously generated in your IT infrastructure
> >>>>>>> contains a definitive record of customers, application performance,
> >>>>>>> security threats, fraudulent activity, and more. Splunk takes this
> >>>>>>> data and makes sense of
>

I must look at committing a patch with an optional value to turn on/off
sorting. At the time we had some deadlines that meant I could not do this
and then got caught up with other items.
On Tuesday, November 22, 2011, Olivier Chirouze <
olivier.chirouze+jsonlib@...> wrote:
> Funny :-) Thanks for sharing the feedback.
> That proves how useful this line is! I don't really like that solution
though...
> In the meantime, I implemented a solution with more lines of code but
that seems to get all I need:
> - a xml2json.xsl stylesheet for XML => JSON (advantage: can use
"BadgerFish" convention)
> - jettison for JSON => XML (but quite complicated to implement)
> So, in a word I did without JSON-lib but what a shame!
> Olivier
> On Tue, Nov 22, 2011 at 3:54 PM, Alan Hicks <al.hicks@...> wrote:
>
> We are using this library to convert from JSON to XML and XML to JSON. To
get around the sorting issue we just commented out the call to
"Arrays.sort( names );" in the Serializer. We have been using it like this
since April 2010 with no issues.
>
> On Tuesday, November 22, 2011, Olivier Chirouze <
olivier.chirouze+jsonlib@...> wrote:
>> I though the "reply-all" was set to reply to
json-lib-user@...! :-)
>> Thanks for your reply anyway. Hope someone can react since I could not
play with bug reports on Sourceforge!
>> Olivier
>>
>> On Tue, Nov 22, 2011 at 3:25 PM, Morgan Packard <morgan@...>
wrote:
>>>
>>> I'm afraid I'm just a dumb user of this project, I'm not involved in
authoring or maintaining it in any way, so i'm not the right guy to ask
about line 942.
>>> -Morgan
>>>
>>> On Tue, Nov 22, 2011 at 3:52 AM, Olivier Chirouze <
olivier.chirouze+jsonlib@...> wrote:
>>>>
>>>> Ok, I found what I see as a very strange... bug?
>>>> Line 942 of XMLSerializer.java, in method processJSONObject(), I
found...
>>>> Arrays.sort( names );
>>>> Why is it there for? I don't see the point in sorting elements,
especially if the output is to be an XML. To me this line is 100% useless.
>>>> I found existing bug entries on sourceforge and will try to push the
resolution of these.
>>>> Olivier
>>>>
>>>> On Tue, Nov 22, 2011 at 9:11 AM, Olivier Chirouze <
olivier.chirouze+jsonlib@...> wrote:
>>>>>
>>>>> I agree with you.
>>>>> But XML elements ARE ordered, right?
>>>>> So, when one passes a list of JSON objects in a specific order, why
change that order when converting to XML???
>>>>>
>>>>> On Mon, Nov 21, 2011 at 5:49 PM, Morgan Packard <
morgan@...> wrote:
>>>>>>
>>>>>> I was under the impression that json dictionaries are unordered
according to the spec.
>>>>>> from json.org:
>>>>>>
>>>>>> JSON is built on two structures:
>>>>>>
>>>>>> A collection of name/value pairs. In various languages, this is
realized as an object, record, struct, dictionary, hash table, keyed list,
or associative array.
>>>>>> An ordered list of values. In most languages, this is realized as
an array, vector, list, or sequence.
>>>>>>
>>>>>> On Mon, Nov 21, 2011 at 11:45 AM, Olivier Chirouze <
olivier.chirouze+jsonlib@...> wrote:
>>>>>>>
>>>>>>> Hi there,
>>>>>>> I am playing with JSON lib conversion from JSON to XML and the
opposite.
>>>>>>> I am now facing a strange issue: converting from json string to XML
seems to loose the order of elements in the process.
>>>>>>> However in debug I can make sure the "insertOrder" property of my
JSONObject is right! But xmlSerializer.write(myJSONObject) returns an XML
string where child elements have been mixed up (seems to be exactly the
opposite order!!...)
>>>>>>> What should I do?
>>>>>>> Thanks
>>>>>>>
------------------------------------------------------------------------------
>>>>>>> All the data continuously generated in your IT infrastructure
>>>>>>> contains a definitive record of customers, application performance,
>>>>>>> security threats, fraudulent activity, and more. Splunk takes this
>>>>>>> data and makes sense of

Funny :-) Thanks for sharing the feedback.
That proves how useful this line is! I don't really like that solution
though...
In the meantime, I implemented a solution with more lines of code but that
seems to get all I need:
- a xml2json.xsl stylesheet for XML => JSON (advantage: can use
"BadgerFish" convention)
- jettison for JSON => XML (but quite complicated to implement)
So, in a word I did without JSON-lib but what a shame!
Olivier
On Tue, Nov 22, 2011 at 3:54 PM, Alan Hicks <al.hicks@...> wrote:
> We are using this library to convert from JSON to XML and XML to JSON. To
> get around the sorting issue we just commented out the call to
> "Arrays.sort( names );" in the Serializer. We have been using it like this
> since April 2010 with no issues.
>
>
> On Tuesday, November 22, 2011, Olivier Chirouze <
> olivier.chirouze+jsonlib@...> wrote:
> > I though the "reply-all" was set to reply to
> json-lib-user@...! :-)
> > Thanks for your reply anyway. Hope someone can react since I could not
> play with bug reports on Sourceforge!
> > Olivier
> >
> > On Tue, Nov 22, 2011 at 3:25 PM, Morgan Packard <
> morgan@...> wrote:
> >>
> >> I'm afraid I'm just a dumb user of this project, I'm not involved in
> authoring or maintaining it in any way, so i'm not the right guy to ask
> about line 942.
> >> -Morgan
> >>
> >> On Tue, Nov 22, 2011 at 3:52 AM, Olivier Chirouze <
> olivier.chirouze+jsonlib@...> wrote:
> >>>
> >>> Ok, I found what I see as a very strange... bug?
> >>> Line 942 of XMLSerializer.java, in method processJSONObject(), I
> found...
> >>> Arrays.sort( names );
> >>> Why is it there for? I don't see the point in sorting elements,
> especially if the output is to be an XML. To me this line is 100% useless.
> >>> I found existing bug entries on sourceforge and will try to push the
> resolution of these.
> >>> Olivier
> >>>
> >>> On Tue, Nov 22, 2011 at 9:11 AM, Olivier Chirouze <
> olivier.chirouze+jsonlib@...> wrote:
> >>>>
> >>>> I agree with you.
> >>>> But XML elements ARE ordered, right?
> >>>> So, when one passes a list of JSON objects in a specific order, why
> change that order when converting to XML???
> >>>>
> >>>> On Mon, Nov 21, 2011 at 5:49 PM, Morgan Packard <
> morgan@...> wrote:
> >>>>>
> >>>>> I was under the impression that json dictionaries are unordered
> according to the spec.
> >>>>> from json.org:
> >>>>>
> >>>>> JSON is built on two structures:
> >>>>>
> >>>>> A collection of name/value pairs. In various languages, this is
> realized as an object, record, struct, dictionary, hash table, keyed list,
> or associative array.
> >>>>> An ordered list of values. In most languages, this is realized as
> an array, vector, list, or sequence.
> >>>>>
> >>>>> On Mon, Nov 21, 2011 at 11:45 AM, Olivier Chirouze <
> olivier.chirouze+jsonlib@...> wrote:
> >>>>>>
> >>>>>> Hi there,
> >>>>>> I am playing with JSON lib conversion from JSON to XML and the
> opposite.
> >>>>>> I am now facing a strange issue: converting from json string to XML
> seems to loose the order of elements in the process.
> >>>>>> However in debug I can make sure the "insertOrder" property of my
> JSONObject is right! But xmlSerializer.write(myJSONObject) returns an XML
> string where child elements have been mixed up (seems to be exactly the
> opposite order!!...)
> >>>>>> What should I do?
> >>>>>> Thanks
> >>>>>>
> ------------------------------------------------------------------------------
> >>>>>> All the data continuously generated in your IT infrastructure
> >>>>>> contains a definitive record of customers, application performance,
> >>>>>> security threats, fraudulent activity, and more. Splunk takes this
> >>>>>> data and makes sense of it. IT sense. And common sense.
> >>>>>> http://p.sf.net/sfu/splunk-novd2d
> >>>>>> _______________________________________________
> >>>>>> json-lib-user mailing list
> >>>>>> json-lib-user@...
> >>>>>> https://lists.sourceforge.net/lists/listinfo/json-lib-user
> >>>>>>
> >>>>>
> >>>>
> >>>
> >>
> >
> >
>

We are using this library to convert from JSON to XML and XML to JSON. To
get around the sorting issue we just commented out the call to
"Arrays.sort( names );" in the Serializer. We have been using it like this
since April 2010 with no issues.
On Tuesday, November 22, 2011, Olivier Chirouze <
olivier.chirouze+jsonlib@...> wrote:
> I though the "reply-all" was set to reply to
json-lib-user@...! :-)
> Thanks for your reply anyway. Hope someone can react since I could not
play with bug reports on Sourceforge!
> Olivier
>
> On Tue, Nov 22, 2011 at 3:25 PM, Morgan Packard <morgan@...>
wrote:
>>
>> I'm afraid I'm just a dumb user of this project, I'm not involved in
authoring or maintaining it in any way, so i'm not the right guy to ask
about line 942.
>> -Morgan
>>
>> On Tue, Nov 22, 2011 at 3:52 AM, Olivier Chirouze <
olivier.chirouze+jsonlib@...> wrote:
>>>
>>> Ok, I found what I see as a very strange... bug?
>>> Line 942 of XMLSerializer.java, in method processJSONObject(), I
found...
>>> Arrays.sort( names );
>>> Why is it there for? I don't see the point in sorting elements,
especially if the output is to be an XML. To me this line is 100% useless.
>>> I found existing bug entries on sourceforge and will try to push the
resolution of these.
>>> Olivier
>>>
>>> On Tue, Nov 22, 2011 at 9:11 AM, Olivier Chirouze <
olivier.chirouze+jsonlib@...> wrote:
>>>>
>>>> I agree with you.
>>>> But XML elements ARE ordered, right?
>>>> So, when one passes a list of JSON objects in a specific order, why
change that order when converting to XML???
>>>>
>>>> On Mon, Nov 21, 2011 at 5:49 PM, Morgan Packard <
morgan@...> wrote:
>>>>>
>>>>> I was under the impression that json dictionaries are unordered
according to the spec.
>>>>> from json.org:
>>>>>
>>>>> JSON is built on two structures:
>>>>>
>>>>> A collection of name/value pairs. In various languages, this is
realized as an object, record, struct, dictionary, hash table, keyed list,
or associative array.
>>>>> An ordered list of values. In most languages, this is realized as
an array, vector, list, or sequence.
>>>>>
>>>>> On Mon, Nov 21, 2011 at 11:45 AM, Olivier Chirouze <
olivier.chirouze+jsonlib@...> wrote:
>>>>>>
>>>>>> Hi there,
>>>>>> I am playing with JSON lib conversion from JSON to XML and the
opposite.
>>>>>> I am now facing a strange issue: converting from json string to XML
seems to loose the order of elements in the process.
>>>>>> However in debug I can make sure the "insertOrder" property of my
JSONObject is right! But xmlSerializer.write(myJSONObject) returns an XML
string where child elements have been mixed up (seems to be exactly the
opposite order!!...)
>>>>>> What should I do?
>>>>>> Thanks
>>>>>>
------------------------------------------------------------------------------
>>>>>> All the data continuously generated in your IT infrastructure
>>>>>> contains a definitive record of customers, application performance,
>>>>>> security threats, fraudulent activity, and more. Splunk takes this
>>>>>> data and makes sense of it. IT sense. And common sense.
>>>>>> http://p.sf.net/sfu/splunk-novd2d
>>>>>> _______________________________________________
>>>>>> json-lib-user mailing list
>>>>>> json-lib-user@...
>>>>>> https://lists.sourceforge.net/lists/listinfo/json-lib-user
>>>>>>
>>>>>
>>>>
>>>
>>
>
>

I though the "reply-all" was set to reply to
json-lib-user@...! :-)
Thanks for your reply anyway. Hope someone can react since I could not play
with bug reports on Sourceforge!
Olivier
On Tue, Nov 22, 2011 at 3:25 PM, Morgan Packard <morgan@...>wrote:
> I'm afraid I'm just a dumb user of this project, I'm not involved in
> authoring or maintaining it in any way, so i'm not the right guy to ask
> about line 942.
> -Morgan
>
>
> On Tue, Nov 22, 2011 at 3:52 AM, Olivier Chirouze <
> olivier.chirouze+jsonlib@...> wrote:
>
>> Ok, I found what I see as a very strange... bug?
>>
>> Line 942 of XMLSerializer.java, in method processJSONObject(), I found...
>>
>> Arrays.sort( names );
>>
>> Why is it there for? I don't see the point in sorting elements,
>> especially if the output is to be an XML. To me this line is 100% useless.
>>
>> I found existing bug entries on sourceforge and will try to push the
>> resolution of these.
>>
>> Olivier
>>
>>
>> On Tue, Nov 22, 2011 at 9:11 AM, Olivier Chirouze <
>> olivier.chirouze+jsonlib@...> wrote:
>>
>>> I agree with you.
>>> But XML elements ARE ordered, right?
>>> So, when one passes a list of JSON objects in a specific order, why
>>> change that order when converting to XML???
>>>
>>>
>>> On Mon, Nov 21, 2011 at 5:49 PM, Morgan Packard <
>>> morgan@...> wrote:
>>>
>>>> I was under the impression that json dictionaries are unordered
>>>> according to the spec.
>>>>
>>>> from json.org:
>>>>
>>>> JSON is built on two structures:
>>>>
>>>> - A collection of name/value pairs. In various languages, this is
>>>> realized as an *object*, record, struct, dictionary, hash table,
>>>> keyed list, or associative array.
>>>> - An ordered list of values. In most languages, this is realized as
>>>> an *array*, vector, list, or sequence.
>>>>
>>>>
>>>>
>>>> On Mon, Nov 21, 2011 at 11:45 AM, Olivier Chirouze <
>>>> olivier.chirouze+jsonlib@...> wrote:
>>>>
>>>>> Hi there,
>>>>>
>>>>> I am playing with JSON lib conversion from JSON to XML and the
>>>>> opposite.
>>>>> I am now facing a strange issue: converting from json string to XML
>>>>> seems to loose the order of elements in the process.
>>>>> However in debug I can make sure the "insertOrder" property of my
>>>>> JSONObject is right! But xmlSerializer.write(myJSONObject) returns an XML
>>>>> string where child elements have been mixed up (seems to be exactly the
>>>>> opposite order!!...)
>>>>>
>>>>> What should I do?
>>>>>
>>>>> Thanks
>>>>>
>>>>>
>>>>> ------------------------------------------------------------------------------
>>>>> All the data continuously generated in your IT infrastructure
>>>>> contains a definitive record of customers, application performance,
>>>>> security threats, fraudulent activity, and more. Splunk takes this
>>>>> data and makes sense of it. IT sense. And common sense.
>>>>> http://p.sf.net/sfu/splunk-novd2d
>>>>> _______________________________________________
>>>>> json-lib-user mailing list
>>>>> json-lib-user@...
>>>>> https://lists.sourceforge.net/lists/listinfo/json-lib-user
>>>>>
>>>>>
>>>>
>>>
>>
>

Hi there,
I am playing with JSON lib conversion from JSON to XML and the opposite.
I am now facing a strange issue: converting from json string to XML seems
to loose the order of elements in the process.
However in debug I can make sure the "insertOrder" property of my
JSONObject is right! But xmlSerializer.write(myJSONObject) returns an XML
string where child elements have been mixed up (seems to be exactly the
opposite order!!...)
What should I do?
Thanks

Hi there,
I am playing with JSON lib conversion from JSON to XML and the opposite.
I am now facing a strange issue: converting from json string to XML seems
to loose the order of elements in the process.
However in debug I can make sure the "insertOrder" property of my
JSONObject is right! But xmlSerializer.write(myJSONObject) returns an XML
string where child elements have been mixed up (seems to be exactly the
opposite order!!...)
What should I do?
Thanks
Olivier

Hi there,
I am playing with JSON lib conversion from JSON to XML and the opposite.
I am now facing a strange issue: converting from json string to XML seems
to loose the order of elements in the process.
However in debug I can make sure the "insertOrder" property of my
JSONObject is right! But xmlSerializer.write(myJSONObject) returns an XML
string where child elements have been mixed up (seems to be exactly the
opposite order!!...)
What should I do?
Thanks
Olivier

Hello Json-lib group member,
I searched a little for any similar post to this but in vain. Sorry if my
search was not sufficient and this post is redundant.
Using json-lib-2.4-jdk13.jar, I encountered an error, running an application
on JVM 1.4. I tracked down in the source and now am able to point out where
(net.sf.json.AbstractJSON.removeInstance(Object)) an Java 1.5 API used in
this library. The java.lang.ThreadLocal.remove() is a method available only
since 1.5. Though it is used in the above mentioned method.
Can anyone confirm me if my following correction is functionnally OK?
abstract class AbstractJSON {
private static class CycleSet extends ThreadLocal {
// ... add the following method
public void remove() {
set(initialValue());
}
}
// ...
I wonder if you manage to compile the jdk1.3 version library without any
compilation error?
Best regards,
Masaru

XMLSerializer.getType( Element element, String defaultType ) should never
return a null or there can be NullPointerExceptions when it tries to convert
XML into JSON.
This happens when an attribute is named "type", for example, attempting to
convert this to JSON will throw a NullPointerException: <myelement
type="mytype"><subelement>a</subelement><subelement>b</subelement></myelement>
Luis

On Tue, 14 Jun 2011 13:20:20 +0200, Elyes Lehtihet wrote:
> Hi,
> First of all, thanks for this tool, found it very useful.
> We noticed a little bug in the way it handles the following
> conversion to JSON from a String:
> What should be converted to a JSON Object :
> "regexp":"[0-9]{1,6}[a-zA-Z]"
> is converted (truncated) to JSON-ARRAY - "regexp":["0-9"]
> Regards,
> -EL
Same result for the follwing String:
"[0-9]{9,10}[a-zA-Z0-9]" --> ["0-9"]

Hi,
First of all, thanks for this tool, found it very useful.
We noticed a little bug in the way it handles the following conversion
to JSON from a String:
What should be converted to a JSON Object :
"regexp":"[0-9]{1,6}[a-zA-Z]"
is converted (truncated) to JSON-ARRAY - "regexp":["0-9"]
Regards,
-EL

Hi All,
I am using json-lib for converting my java object to json array. I
encountered the error "net.sf.json.JSONException: There is a cycle in the
hierarchy!" not more often but want to remove it. I am little confused about
the statement "*when parsing, JSONObject and JSONArray will check for cycles
in the hierarchy, throwing an exception if one is found. You can change this
behavior by registering a CycleDetectionStrategy*" in
http://json-lib.sourceforge.net/usage.html. i.e. i want to know how to use
LENIENT approach for my application or i can Override the method
inside *CycleDetectionStrategy
*for my usage.
Please help
Thanking you in advance.
--
--------------------------------------------------------------
Thanks & Regards,
*Pravin Chikhale*
Software Engineer,
LinkedIn: http://in.linkedin.com/in/pravinchk/
================================

VTD-XML 2.10 is now released. It can be downloaded at
https://sourceforge.net/projects/vtd-xml/files/vtd-xml/ximpleware_2.10/.
This release includes a number of new features and enhancement.
* The core API of VTD-XML has been expanded. Users can now perform
cut/paste/insert on an empty element.
* This release also adds the support of deeper location cache support for
parsing and indexing. This feature is useful for application performance
tuning for
processing various XML documents.
* The java version also added support for processing zip and gzip files.
Direct processing of httpURL based XML is enhanced.
* Extended Java version now support Iso-8859-10~16 encoding.
* A full featured C++ port is released.
* C version of VTD-XML now make use of thread local storage to achieve
thread safety for multi-threaded application.
* There are also a number of bugs fixed. Special thanks to Jozef Aerts, John
Sillers, Chris Tornau and a number of other users for input and suggestions