Giter Club home page Giter Club logo

json-smart-v2's Introduction

json-smart-v2

Build Status Maven Central Coverage Status

Json-smart development started in 2010, when SQL servers did not support native JSON fields, NoSQL databases were slowly emerging, and all the existing JSON APIs were bogus. I wrote lots of tests to benchmark and compare JSON java parsers.

I never liked SQL databases because it's almost impossible to update a data model without impacting the production platform. Adding a column is a terrible operation.

So I started json-smart. All non-indexed data in my datastores were stored in a column as a serialized JSON message. To fit MySQL varchar(255) fields, I tried to make my JSON as small as possible, so json-smart is optimized to produce small JSON-like Strings.

Now times have changed: most of the JSON APIs are now stable, and I'm now using document-oriented databases and JSON-native SQL types.

So I do not use my json-smart anymore. I had fun with this project. If you want to apply some change on json-smart create a pull request with lots of JUnit tests.

WIKI is here

Changelog

V 2.5.1 (2024-03-14)

  • Bump all dependencies.
  • Fix OSGi import package version for net.minidev.asm. PR 180

V 2.5.0 (2023-07-10)

  • Add flag to drop the limit of json depth. PR 156

V 2.4.11 (2023-05-18)

  • Fix error in isWritable in accessor-smart. PR 147
  • Update json-smart dependency to use accessor-smart:2.4.11

V 2.4.10 (2023-03-17)

  • Fix unstacking issue with more than 400 elements in an array.

V 2.4.9 (2023-03-07)

  • Add depth limit of 400 when parsing JSON.

V 2.4.8 (2022-02-13)

  • Fix the incorrect double compare with e,E+,e+ PR 77

V 2.4.7 (2021-06-02)

  • full timezone support in date parsing
  • set default charset to UTF-8 when parsing byte[] contents
  • overwride system default encoding when parssing bytes[] PR 71

V 2.4.6 (2021-04-23)

  • Correct publish issue 3th time issue 69
  • Support latest asm in accessor-smart issue 70
  • Drop legacy parent pom

V 2.4.5 (2021-04-19)

  • Correct publish issue 2nd time issue 69

V 2.4.4 (2021-04-17)

  • Correct publish issue 1st time issue 69
  • fix ArrayIndexOutOfBoundsException issue 68

V 2.4.2 (2021-04-04)

V 2.4.2 (2021-04-03)

  • add BIG_DIGIT_UNRESTRICTED to avoid BigDigit usage on some Double.
  • fix CVE-2021-27568
  • java 11 build

V 2.3.1 (2021-05-02)

  • Fixes issue #60 (CVE-2021-27568)
  • full timezone support in date parsing

V 2.3 (2017-03-26)

  • Patch 37 issue 37
  • Explicite support of char 127 issue 18
  • Integrate json-smart-action from Eitan Raviv PR 31
  • Remove hard codded e.printStackTrace() issue 33
  • Improve date parsing code to support all timeZones issue 29

V 2.2.2

  • Fix support for default java datetime format for US locale
  • Update my time Zone from Paris to San Francisco.

V 2.2.1 (2015-10-08)

  • Fix issue in strict mode issue gh-17
  • Add a licence Copy at the root project level issue gh-16
  • Change InputStream input reading to use UTF8. issue 48

V 2.2 (2015-07-29)

  • Rename asm to accessors-smart due to conflict name with asm.ow2.org lib. fix PR-10
  • Fix OSGI error fix PR-2
  • Add support for BigDecimal
  • Improve JSONObject.getAsNumber() helper
  • Add a Field Remaper

V 2.1.0 (2014-10-19)

  • net.minidev.json.mapper renamed to net.minidev.json.writer
  • Add ACCEPT_TAILLING_SPACE Parssing Flag.
  • Mapper classes now non static.
  • Reader mapper are now available in net.minidev.json.reader.JsonReader class
  • Writer mapper are now available in net.minidev.json.writer.JsonWriter class

V 2.0 (2014-08-12)

  • Fix Double Identification issue 44
  • Fix Collection Interface Serialisation
  • Fix security Exception in ASM code
  • Project moved to GitHub
  • Fix issue 42

V 2.0-RC3 (2013-08-14)

  • Add custom data binding inside the ASM layer.
  • Add Date support
  • Add \x escape sequence support issue 39
  • fix issue issue 37

V 2.0-RC2 (2012-04-03)

V 2.0-RC1 (2012-02-18)

  • speed improvement in POJO manipulation
  • add JSONStyle.LT_COMPRESS predefined generate strct json, but ignoring / escapement.

json-smart-v2's People

Contributors

alanscut avatar amergey avatar coheigea avatar dependabot[bot] avatar dpeger avatar erav avatar ewoelfel avatar grimoren avatar harikrishna553 avatar hboutemy avatar jochenberger avatar kirilldev avatar mattnelson avatar msqr avatar pcy190 avatar shoothzj avatar tobi5775 avatar urielch avatar wirelessben avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

json-smart-v2's Issues

Support LocalDate

Getting this exception from jsonsmart when trying to serialize a LocalDate:
java.lang.IllegalAccessError: tried to access field java.time.LocalDate.month from class net.minidev.asm.java.time.LocalDateAccAccess

For context, the contributor of dsljson added a serie of new tests to java-json-benchmark that covers types such as LocalDate, OffsetDateTime and UUID... jsonsmart currently does not handle any of these 3 types, which means it is excluded from this particular test suite, but I'd like to bring it back...

Implementing custom serializers works, but since the docs showing how to implement a custom deserializer are missing, I am a little stuck here...

when we release new version to fix CVE-2021-27568

hi, when we release new version to fix CVE-2021-27568. Now, the latest version is 2.3 in maven repository.
About CVE-2021-27568 :An issue was discovered in netplex json-smart-v1 through 2015-10-23 and json-smart-v2 through 2.4. An exception is thrown from a function, but it is not caught, as demonstrated by NumberFormatException. When it is not caught, it may cause programs using the library to crash or expose sensitive information.

TestDateConvert failures with UTC timezone

Hi,

I noticed that TestDateConvert has failures if the local timezone is set to UTC. The tests work fine with a timezone set to Europe/Paris.

Running net.minidev.asm.TestDateConvert
can not parse:lundi 23 janvier 2012 13 h 42 UTC - DateFormat.0
java.lang.NumberFormatException: For input string: "UTC"
        at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
        at java.lang.Integer.parseInt(Integer.java:580)
        at java.lang.Integer.parseInt(Integer.java:615)
        at net.minidev.asm.ConvertDate.addHour(ConvertDate.java:264)
        at net.minidev.asm.ConvertDate.getDDMMYYYY(ConvertDate.java:229)
        at net.minidev.asm.ConvertDate.convertToDate(ConvertDate.java:139)
        at net.minidev.asm.TestDateConvert.fullTestDate(TestDateConvert.java:75)
        at net.minidev.asm.TestDateConvert.testDateLocalized(TestDateConvert.java:62)
        at net.minidev.asm.TestDateConvert.testDateFRANCE(TestDateConvert.java:43)

can not parse:Montag, 23. Januar 2012 13:42 Uhr UTC - DateFormat.0
java.lang.NumberFormatException: For input string: "UTC"
        at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
        at java.lang.Integer.parseInt(Integer.java:580)
        at java.lang.Integer.parseInt(Integer.java:615)
        at net.minidev.asm.ConvertDate.addHour(ConvertDate.java:264)
        at net.minidev.asm.ConvertDate.getDDMMYYYY(ConvertDate.java:229)
        at net.minidev.asm.ConvertDate.convertToDate(ConvertDate.java:139)
        at net.minidev.asm.TestDateConvert.fullTestDate(TestDateConvert.java:75)
        at net.minidev.asm.TestDateConvert.testDateLocalized(TestDateConvert.java:62)
        at net.minidev.asm.TestDateConvert.testDateGERMANY(TestDateConvert.java:51)

testDateCANADA(net.minidev.asm.TestDateConvert)  Time elapsed: 0.007 sec  <<< FAILURE!
junit.framework.ComparisonFailure: expected:<23/01/2012 [13]:42:59> but was:<23/01/2012 [01]:42:59>
        at net.minidev.asm.TestDateConvert.fullTestDate(TestDateConvert.java:83)
        at net.minidev.asm.TestDateConvert.testDateLocalized(TestDateConvert.java:62)
        at net.minidev.asm.TestDateConvert.testDateCANADA(TestDateConvert.java:47)

2.1.0 version do not export the new packages

It seems the reader and writer packages are supposed to be part of the API, though they are not exported in the released OSGi bundle.
An attempt to fix this problem is in the commit 7f22d7a (part of the pull request #6, which also addresses the issue of version compatibility by re-adding the deprecated parts used by for example the jayway/json-path project).

Unicode characters are not correctly parsed from byte[] if default charset is not UTF-8

The TestUtf8.supportI18nBytes test is currently broken on windows systems. Actually in my IDE (IntelliJ) the test is green. but the maven test target fails both in the IDE and on command line:

[ERROR] Failures:
[ERROR] TestUtf8.supportI18nBytes:62 Parsing bytes[] Amharic text ==> expected: <አማርኛ> but was: <አማርኛ>
[ERROR] TestUtf8.supportI18nBytes:62 Parsing bytes[] Malayalam text ==> expected: <മലയാളം> but was: <മലയാളം>
[ERROR] TestUtf8.supportI18nBytes:62 Parsing bytes[] Assyrian Neo-Aramaic text ==> expected: <ܐܬܘܪܝܐ> but was: <Ü?ܬܘܪÜ?Ü?>
[ERROR] TestUtf8.supportI18nBytes:62 Parsing bytes[] Georgian text ==> expected: <მარგალური> but was: <მáƒ?რგáƒ?ლური>
[ERROR] TestUtf8.supportI18nBytes:62 Parsing bytes[] Sinhala text ==> expected: <සිංහල ජාතිය> but was: <සිංහල ජà·?තිය>
[ERROR] TestUtf8.supportI18nBytes:62 Parsing bytes[] Japanese text ==> expected: <日本語> but was: <日本語>
[ERROR] TestUtf8.supportI18nBytes:62 Parsing bytes[] Russian text ==> expected: <Русский> but was: <РуÑ?Ñ?кий>
[ERROR] TestUtf8.supportI18nBytes:62 Parsing bytes[] Farsi text ==> expected: <فارسی> but was: <Ù?ارسی>
[ERROR] TestUtf8.supportI18nBytes:62 Parsing bytes[] Korean text ==> expected: <한국어> but was: <한국어>
[ERROR] TestUtf8.supportI18nBytes:62 Parsing bytes[] Armenian text ==> expected: <Հայերեն> but was: <Õ€Õ¡ÕµÕ¥Ö€Õ¥Õ¶>
[ERROR] TestUtf8.supportI18nBytes:62 Parsing bytes[] Hindi text ==> expected: <हिन्दी> but was: <हिनà¥?दी>
[ERROR] TestUtf8.supportI18nBytes:62 Parsing bytes[] Hebrew text ==> expected: <עברית> but was: <עברית>
[ERROR] TestUtf8.supportI18nBytes:62 Parsing bytes[] Chinese text ==> expected: <中文> but was: <中文>

The problem seems to be the creation of String using the system's default charset in JSONParserByteArray.extractString

xs = new String(in, beginIndex, endIndex - beginIndex);

and JSONParserByteArray.extractStringTrim

Where is the @JsonProperty annotation ?

Some json fields are not nice or impossible to write in POJOs. For instance:

{"_id": "theid" }
{"200": "the200" }

usually, json framworks provides annotations to specify the name of the json property. for instance:

public class ThePojo { @JsonProperty("_id") public String id; }

Where is this feature in json-smart?

release version 2.3?

I see 5cc0cd2, but I'm struggling to find a "published" jar for version 2.3, similar to https://mvnrepository.com/artifact/net.minidev/json-smart/2.2.1, or even a git tag. I'd love to see the current code in a jar that's more easily accessible. Can you help me with a repo that has it, or help publish it?

Specifically, I'm looking for a version of json-smart that depends on accessors-smart version 1.2, or something that no longer includes the org/objectweb/asm classes.

Thanks much.

-DB

Ability to write Indented JSON

It will be awesome if we can add a new JSONStyle to write an indented human readable JSON object

Something like:

try (final PrintWriter writer = response.getWriter())
{
     JSONObject.writeJSON(root, writer, JSONStyle.INDENT);
     response.flushBuffer();
}

Generating:

{
    "list": [
        {
            "num": "123456",
            "mail": "[email protected]",
            "tel": "+33611111111",
            "date": "2020-10-20"
        },
        {
            "num": "123457",
            "mail": "[email protected]",
            "tel": "+33622222222",
            "date": "2020-10-21"
        }
    ]
}

Embedded ASM clashes with other dependencies

The ASM embedded in accessors-smart must have renamed packages otherwise it will class with other libraries using ASM in a different version. You use the bundle plugin to do that but this functionality is only a good idea in an OSGi context because there the ClassLoader can hide the dependency from the rest of the application.

Character U+007F in string is not accepted in MODE_RFC4627

new JSONParser(JSONParser.MODE_RFC4627).parse(String.format("[\"%c\"]", 127)); throws exception, but expected behavior is to return array containing string of one character (unicode codepoint 127).

According to RFC:

All Unicode characters may be placed within the
quotation marks except for the characters that must be escaped:
quotation mark, reverse solidus, and the control characters (U+0000
through U+001F).

Incorrectly parsing arbitrary strings

json-smart is not parsing strings encoded from random bytes correctly. This seems like a bug in the parser unless json-smart is not meant to support arbitrary strings. Is there a different way to read arbitrary strings correctly with json-smart?

I used org.json to stringify a simple json object and read it via json-smart, but it fails. Bug report code below:

    byte[] random = new byte[256];
    for (int j = 0; j < random.length; j++)
        random[j] = (byte) (Math.random() * Short.MAX_VALUE);
    String str = new String(random, "ISO-8859-1");
    JSONObject json = new JSONObject();
    json.put("key", str);
    String jStr = json.toString();
    net.minidev.json.JSONObject jsonS = (net.minidev.json.JSONObject) net.minidev.json.JSONValue
            .parse(jStr);
    String jsStr = (String) jsonS.toString();
    assert (jStr.equals(jsStr)) : "\n"+jStr + "\n !=\n"+jsStr + "\n lengths=" + jStr.length() + " ," + jsStr.length() ;

Accepts invalid JSON

The following test fails, {"foo":"bar"x} is accepted as valid JSON.

public void testDataAfterValue() throws Exception {
    String s = "{\"foo\":\"bar\"x}";
    MustThrows.testInvalidJson(s, JSONParser.MODE_STRICTEST | JSONParser.ACCEPT_TAILLING_SPACE, ParseException.ERROR_UNEXPECTED_TOKEN);
}

License of Project

Hello,
Thanks for this nice library.
Looking into code, I don't see any License mention ?

What is its license ? Apache2 or something else ?

Thanks
Regards
Philippe M.
@philmdot

java.lang.IncompatibleClassChangeError: Found class org.objectweb.asm.MethodVisitor, but interface was expected

When included in a project that has a dependency on org.ow2.asm.asm-4.1

java.lang.IncompatibleClassChangeError: Found class org.objectweb.asm.MethodVisitor, but interface was expected
    at net.minidev.asm.BeansAccessBuilder.bulid(BeansAccessBuilder.java:118)
    at net.minidev.asm.BeansAccess.get(BeansAccess.java:111)
    at net.minidev.json.writer.BeansMapper$Bean.<init>(BeansMapper.java:45)
    at net.minidev.json.writer.JsonReader.getMapper(JsonReader.java:119)
    at net.minidev.json.JSONValue.parse(JSONValue.java:206)
    at com.jayway.jsonpath.internal.spi.mapper.JsonSmartMappingProvider.map(JsonSmartMappingProvider.java:92)
    at com.jayway.jsonpath.internal.JsonReader.convert(JsonReader.java:171)
    at com.jayway.jsonpath.internal.JsonReader.read(JsonReader.java:137)

StackOverflowError of java.nio.file.Path as a special iterable type invoke toJSONString()

Hello Friends!

Error is thrown when I execute the following unit test, i found that when the generic object of the iterator is another iterator obj for example Path and then error occur.

About Signatures:
net.minidev.json.JSONValue#writeJSONString(java.lang.Object, java.lang.Appendable, net.minidev.json.JSONStyle)
net.minidev.json.reader.JsonWriterI#writeJSONString

@Test
    public void test() {
        Map<String, Object> cachedTable1 = new LinkedHashMap<>();
        Iterable<Path> path = Paths.get("/home");
        cachedTable1.put("1", path);
        try {
            JSONValue.toJSONString(cachedTable1);
        } catch (Error e) {
            Assertions.assertEquals("java.lang.StackOverflowError", e.getClass().getName());
        }
    }

ArrayIndexOutOfBoundsException in parser

Same as
netplex/json-smart-v1#10

The code base is at

protected int indexOf(char c, int pos) {
for (int i = pos; pos < len; i++)
if (in[i] == (byte) c)
return i;
return -1;
}

It shouldn't be the pos to be checked less than len. Instead, the i should be checked. The correct way in line 79 is:

for (int i = pos; i < len; i++) 

Any input with unclosed single quotation mark could trigger this. Like the input of 'c, cause the ArrayIndexOutOfBoundsException

mvn install test failure

mvn install in parent directory:
Running net.minidev.asm.ASMTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.289 sec
Running net.minidev.asm.TestNewInstance
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.001 sec
Running net.minidev.asm.TestDateConvert
can not parse:lundi 23 janvier 2012 13 h 42 PST - DateFormat.0
java.lang.NumberFormatException: For input string: "PST"
at java.lang.NumberFormatException.forInputString(NumberFormatException.
java:65)
at java.lang.Integer.parseInt(Integer.java:492)
at java.lang.Integer.parseInt(Integer.java:527)
at net.minidev.asm.ConvertDate.addHour(ConvertDate.java:264)

Odd classpaths?

Discovered while trying to debug a stack overflow while running toJSONString() on an object which should not do that:
Found writer classes in net/minidev/json/reader/
and found reader classes in net/minidev/json/writer/
Curious: what am I missing?

Can't disable stack traces written to standard error

Is there any way that the calls to write the stack trace to standard out be replaced with calls to a logging framework such as logback, log4j, or slf4j? This would allow filtering of specific log messages.

Here's our problem: We are using JSON smart v2 as a part of the JayWay JSON Path expression processor to parse JSON formatted response messages from REST web services. Our application runs in a Tomcat container, with its standard error being during to a file.

Under certain circumstances, when the JSON Path expression in the response almost perfectly matches the JSON String being processed (I can give you more details if you wish), a stack trace happens on every call and the Tomcat log file grows dramatically quickly. It has reached in excess of 5GB and has caused production problems.

As an example, in the File "JSONValue.java" at lines 203 thru 211 inclusive (with the e.printStackTrace() call at line 208):

public static <T> T parse(String in, Class<T> mapTo) {
    try {
        JSONParser p = new JSONParser(DEFAULT_PERMISSIVE_MODE);
        return p.parse(in, defaultReader.getMapper(mapTo));
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

The call to e.printStackTrace() at line 208 causes a stack trace to be written each time this exception occurs , which can be quite often. Basically, we don't need to see the stack trace.

So, could they be replaced by a logging framework?

I would be more than happy to create a fork or json-smart-v2 and add the logging framework in.

JSONObject as LinkedHashMap

Please, implement JSONObject as LinkedHashMap.

I will let retrieve values by key but also iterate attributes in their insertion-order.

Parent pom for 2.4.4 missing in Maven Central

Thanks for the recent 2.x updates!

On trying to use the new v2.4.4 Maven aborted with the message

Failed to read artifact descriptor for net.minidev:json-smart:jar:2.4.4: Could not find artifact net.minidev:minidev-parent:pom:2.4.3 in central (https://repo.maven.apache.org/maven2)

It appears the parent POM needs to be uploaded to Central as well:

https://search.maven.org/artifact/net.minidev/minidev-parent
https://search.maven.org/artifact/net.minidev/json-smart/2.4.4/bundle

!!!URGENT!!! Upgrading to json-smart 2.4.5 causes missing dependency `net.minidev:accessors-smart:jar:2.4.3`

Upgrading json-smart to 2.4.5 for issue#67 and issue#10.
Forcing json-smart to 2.4.5 with the following:

            <dependency>
                <groupId>net.minidev</groupId>
                <artifactId>json-smart</artifactId>
                <version>2.4.5</version>
            </dependency>

But it causes the following error:

Failed to execute goal on project opensearch-security: Could not resolve dependencies for project org.opensearch:opensearch-security:jar:1.0.0.0-rc1: Could not find artifact net.minidev:accessors-smart:jar:2.4.3 in central (https://repo.maven.apache.org/maven2) -> [Help 1]

Had to force accessors-smart to 2.4.2 with the following to compile:

            <dependency>
                <groupId>net.minidev</groupId>
                <artifactId>accessors-smart</artifactId>
                <version>2.4.2</version>
            </dependency>

Looks like json-smart-2.4.5 upgrades the dependency accessors-smart to 2.4.3, but accessors-smart-2.4.3.jar is unavailable in Maven Central?

Multi-threading issue in JsonWriter

In JsonWriter the variable writerInterfaces is defined as

private LinkedList<WriterByInterface> writerInterfaces;

In JsonValue.java you have the code..

public static void writeJSONString(Object value, Appendable out, JSONStyle compression) throws IOException {
    if (value == null) {
        out.append("null");
        return;
    }
    Class<?> clz = value.getClass();
    @SuppressWarnings("rawtypes")
    JsonWriterI w = defaultWriter.getWrite(clz);
    if (w == null) {
        if (clz.isArray())
            w = JsonWriter.arrayWriter;
        else {
            w = defaultWriter.getWriterByInterface(value.getClass());
            if (w == null)
                w = JsonWriter.beansWriterASM;
            // w = JsonWriter.beansWriter;
        }
        defaultWriter.registerWriter(w, clz);
    }
    w.writeJSONString(value, out, compression);
}

defaultWriter is static. In a multi-threaded app, if call to getWriterByInterface returns null multiple threads could call registerWriter() and the internal LinkedList is not thread safe.

Fix maven-metadata.xml in Central repository

Hello,

I would like to report to you the issue arising when using your library.

Maven tries to download the version 2.3-SNAPSHOT and cannot from the Central repository - leading to random failures.

Can you please update that file and make it available in Central repository?

Thanks a lot for your help

java.lang.UnsupportedOperationException: can't load this type of class file

on Andriod's environment
when call [String s = net.minidev.json.JSONValue.toJSONString(person);] . throw following error:

W/System.err: java.lang.UnsupportedOperationException: can't load this type of class file
W/System.err: at java.lang.ClassLoader.defineClass(ClassLoader.java:265)
W/System.err: at net.minidev.asm.DynamicClassLoader.defineClass(DynamicClassLoader.java:86)
W/System.err: at net.minidev.asm.BeansAccessBuilder.bulid(BeansAccessBuilder.java:313)
W/System.err: at net.minidev.asm.BeansAccess.get(BeansAccess.java:111)
W/System.err: at net.minidev.json.reader.BeansWriterASM.writeJSONString(BeansWriterASM.java:17)
W/System.err: at net.minidev.json.JSONValue.writeJSONString(JSONValue.java:596)
W/System.err: at net.minidev.json.JSONValue.toJSONString(JSONValue.java:632)
W/System.err: at net.minidev.json.JSONValue.toJSONString(JSONValue.java:610)

not able to mnv package successfully on json-smart.

[ERROR] Failures:
[ERROR] TestUtf8.testBytes:51 expected:<[à·ƒà·?à??à·?à?½ à?¢à·?à??à·?à?º]> but was:<[????? ?????]>
[INFO]
[ERROR] Tests run: 116, Failures: 1, Errors: 0, Skipped: 0

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test (default-test) on project json-smart: There are test failures.
[ERROR]
[ERROR] Please refer to D:\json-smart-v2-master\json-smart\target\surefire-reports for the individual test results.
[ERROR] Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.

D:\json-smart-v2-master\json-smart>mvn -version
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: D:\maven\apache-maven-3.6.3\bin..
Java version: 11.0.6, vendor: Oracle Corporation, runtime: C:\Apps\Dvlp\jdk11_64
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

Resolve concrete type during deserialization

Hi All,

Here is unit-test:

import org.junit.Assert;
import net.minidev.json.JSONValue;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

public class DeserializeAbstractClassesTest {

    @Test
    public void deserialize_regular_class() {
        RegularClass regularClass = JSONValue.parse("{\"field\": \"value\"}", RegularClass.class);
        Assert.assertEquals(regularClass.getField(), "value");
    }

    @Test
    public void deserialize_list_of_abstract_classes() {
        ParentClass parentClass = JSONValue.parse("{\"list\":[{\"field\":\"value\"}]}", ParentClass.class);
        Assert.assertTrue(parentClass.getList().get(0) instanceof RegularClass);
    }

    public static abstract class AbstractClass {
    }

    public static class RegularClass extends AbstractClass {
        private String field;

        public String getField() {
            return field;
        }

        public void setField(String field) {
            this.field = field;
        }
    }

    public static class ParentClass {
        private List<AbstractClass> list = new ArrayList<>();

        public List<AbstractClass> getList() {
            return list;
        }

        public void setList(List<AbstractClass> list) {
            this.list = list;
        }
    }

}

It throw InstantiationError in deserialize_list_of_abstract_classes:


java.lang.InstantiationError: DeserializeAbstractClassesTest$AbstractClass
    at DeserializeAbstractClassesTest$AbstractClassAccAccess.newInstance(Unknown Source)
    at net.minidev.json.mapper.BeansMapper$Bean.createObject(BeansMapper.java:88)
    at net.minidev.json.parser.JSONParserBase.readObject(JSONParserBase.java:478)
    at net.minidev.json.parser.JSONParserBase.readMain(JSONParserBase.java:387)
    at net.minidev.json.parser.JSONParserBase.readArray(JSONParserBase.java:257)
    at net.minidev.json.parser.JSONParserBase.readMain(JSONParserBase.java:390)
    at net.minidev.json.parser.JSONParserBase.readObject(JSONParserBase.java:530)
    at net.minidev.json.parser.JSONParserBase.readFirst(JSONParserBase.java:285)
    at net.minidev.json.parser.JSONParserBase.parse(JSONParserBase.java:150)
    at net.minidev.json.parser.JSONParserString.parse(JSONParserString.java:57)
    at net.minidev.json.parser.JSONParser.parse(JSONParser.java:253)
    at net.minidev.json.JSONValue.parse(JSONValue.java:210)
    at DeserializeAbstractClassesTest.deserialize_list_of_abstract_classes(DeserializeAbstractClassesTest.java:18)

As I understand the json-smart can't resolve abstract type (AbstractClass) to regular type (RegularClass). Is it possible to specify it manually (i.e. use attributes)?

Thanks

json-smart 2.0

Is json-smart 2.2.1 compatible with json-smart-1.1.1?

Hi team,

In out project, we have used the json-smart-1.1.1. We need to use Json-path 2.2.0 which is compatible with json-smart 2.2.1 but not with json-smart-1.1.1.

We have to update the json-smart-1.1.1 to json-smart-2.2.1.
Is it compatible? Will moving to 2.2.1 from 1.1.1 works fine?

Thanks,
Mohammed

OSGi support

It would be nice to have OSGi-compatible MANIFEST.MF included (also in its asm dependency) in the generated artifacts.

Last project update on 2021-05-02, New maintainer needed.

I think this project may be unmaintained now. The last commit was over a year ago. Additionally, there are some critical bugs that need to be fixed.

If someone wants to setup up and help maintain it and cut releases I think everyone would appreciate it (but I don't have time)

IllegalAccessError thrown when calling JSONObject.toString

OS: Linux 4.19-MANJARO
Java: 1.8.0_191-b12
Scala: 2.12.6
Play: 2.6.12
Nimbus JOSE 6.2

I'm using the Nimbus JOSE library to create, encrypt and decrypt JWTs. When I serialise the JWT and the Nimbus library then calls JSONObject.toString from net.minidev.json it results in an IllegalAccessError from BeanWriterASM:

play.api.http.HttpErrorHandlerExceptions$$anon$1: Execution exception[[CompletionException: java.lang.IllegalAccessError: java/util/stream/ReferencePipeline$3]] at play.api.http.HttpErrorHandlerExceptions$.throwableToUsefulException(HttpErrorHandler.scala:255) at play.api.http.DefaultHttpErrorHandler.onServerError(HttpErrorHandler.scala:182) at play.core.server.AkkaHttpServer$$anonfun$2.applyOrElse(AkkaHttpServer.scala:320) at play.core.server.AkkaHttpServer$$anonfun$2.applyOrElse(AkkaHttpServer.scala:318) at scala.concurrent.Future.$anonfun$recoverWith$1(Future.scala:413) at scala.concurrent.impl.Promise.$anonfun$transformWith$1(Promise.scala:37) at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:60) at akka.dispatch.BatchingExecutor$AbstractBatch.processBatch(BatchingExecutor.scala:55) at akka.dispatch.BatchingExecutor$BlockableBatch.$anonfun$run$1(BatchingExecutor.scala:91) at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12) Caused by: java.util.concurrent.CompletionException: java.lang.IllegalAccessError: java/util/stream/ReferencePipeline$3 at java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:273) at java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:280) at java.util.concurrent.CompletableFuture.uniApply(CompletableFuture.java:604) at java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:577) at java.util.concurrent.CompletableFuture$Completion.exec(CompletableFuture.java:443) at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289) at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056) at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692) at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157) Caused by: java.lang.IllegalAccessError: java/util/stream/ReferencePipeline$3 at net.minidev.asm.java.util.stream.ReferencePipeline$3AccAccess.get(Unknown Source) at net.minidev.json.reader.BeansWriterASM.writeJSONString(BeansWriterASM.java:21) at net.minidev.json.JSONValue.writeJSONString(JSONValue.java:586) at net.minidev.json.reader.JsonWriter.writeJSONKV(JsonWriter.java:392) at net.minidev.json.reader.JsonWriter$7.writeJSONString(JsonWriter.java:145) at net.minidev.json.reader.JsonWriter$7.writeJSONString(JsonWriter.java:1) at net.minidev.json.JSONObject.writeJSON(JSONObject.java:186) at net.minidev.json.JSONObject.toJSONString(JSONObject.java:74) at net.minidev.json.JSONObject.toString(JSONObject.java:272) at com.nimbusds.jose.Payload.toString(Payload.java:386)

I had thought that this could have been related to but that is reported fixed in Java 9 and backported to 8 in build 102. Upgrading to Java 9 doesn't resolve the issue either. I'm totally stumped as to how to debug this so any help would be greatly appreciated.

Ability to preserve elements order on parse JSON

When I parse a JSON string parameters orders are lost. Even if it doesn't matter in almost all cases, I have a use case where the order need to be preserved.

We can imagine adding a boolean to the parse method to return a new class OrderedJSONObject extending LinkedHashMap:

OrderedJSONObject document = JSONValue.parse(responseStr, true);

Erroneous check in JSONObject merge Method

I noticed a problem in the method protected static JSONArray merge(JSONArray o1, Object o2) of the JSONObject class. It contains the following check:

if (o1 instanceof JSONArray)
    return merge(o1, (JSONArray) o2);

which does not make much sense, since o1 is already of type JSONArray. I believe o2 was meant to be checked here. The implementation would then be analogous to the method protected static JSONObject merge(JSONObject o1, Object o2).

Since I only spotted this by coincidence, I do not know the effects of this bug.

Parser error when ' is found inside "

Parser fails when trying to parse the following content.

{"fieldDataCollection":[{"id":"CL1:COM","commodityUnits":"USD/bbl.","commodityContractDate":"Sep 2018","name":"Generic 1st 'CL' Future","price":67.37,"priceChange1Day":0.17,"percentChange1Day":0.2529760003089905,"lastUpdateEpoch":"1534197994","lowPrice":67.36,"highPrice":67.43,"priceDate":"8/13/2018","priceTime":"6:06 PM","lastUpdateTime":"6:06 PM","lastUpdateISO":"2018-08-13T22:06:34.000Z","userTimeZone":"EDT","longName":"WTI Crude Oil (Nymex)","shortName":"WTI Crude"},{"id":"CO1:COM","commodityUnits":"USD/bbl.","commodityContractDate":"Oct 2018","name":"Generic 1st 'CO' Future","price":72.61,"priceChange1Day":-0.2,"percentChange1Day":-0.2746880054473877,"lastUpdateEpoch":"1534197598","lowPrice":71.04,"highPrice":73.09,"priceDate":"8/13/2018","priceTime":"5:59 PM","lastUpdateTime":"5:59 PM","lastUpdateISO":"2018-08-13T21:59:58.000Z","userTimeZone":"EDT","longName":"Brent Crude (ICE)","shortName":"Brent Crude"},{"id":"CP1:COM","commodityUnits":"JPY/kl","commodityContractDate":"Jan 2019","name":"Generic 1st 'CP' Future","price":48450,"priceChange1Day":140,"percentChange1Day":0.28979501128196716,"lastUpdateEpoch":"1534192201","lowPrice":47420,"highPrice":48620,"priceDate":"8/13/2018","priceTime":"4:30 PM","lastUpdateTime":"4:30 PM","lastUpdateISO":"2018-08-13T20:30:01.000Z","userTimeZone":"EDT","longName":"Crude Oil (Tokyo)","shortName":"Crude Oil (Tokyo)"},{"id":"NG1:COM","commodityUnits":"USD/MMBtu","commodityContractDate":"Sep 2018","name":"Generic 1st 'NG' Future","price":2.925,"priceChange1Day":-0.005,"percentChange1Day":-0.170647993683815,"lastUpdateEpoch":"1534197901","lowPrice":2.923,"highPrice":2.926,"priceDate":"8/13/2018","priceTime":"6:05 PM","lastUpdateTime":"6:05 PM","lastUpdateISO":"2018-08-13T22:05:01.000Z","userTimeZone":"EDT","longName":"Natural Gas (Nymex)","shortName":"Natural Gas (Nymex)"}]}

Are there any known issues related to putting a List<JSONObject> into a JSONObject?

I have been having runaway stack exceptions apparently during an operation that looks like this:

data.put(prop, edges) where
data = JSONObject, prop = "InEdges" and edges are either List or JSONArray.

If I stringify the edge objects, then edges = List and I get no stack overflows, but downstream, I am forced to convert the strings back to JSONObjects. I'm running 2.2.1

Thanks in advance. Jack

Uncaught Exception in Parser

The parser fails to throw the ParseException when the parser expects the input to be of the float number type AND the input not being a valid number. This can lead to uncaught exceptions by unexpected input, which may lead to Denial-of-Service (DoS).

protected Number extractFloat() throws ParseException {
if (!acceptLeadinZero)
checkLeadinZero();
if (!useHiPrecisionFloat)
return Float.parseFloat(xs);
if (xs.length() > 18) // follow JSonIJ parsing method
return new BigDecimal(xs);
return Double.parseDouble(xs);
}

Parser Input of "-." or "2e+" or "[45e-" will crash with a NumberFormatException.

== Java Exception: java.lang.NumberFormatException: For input string: "-."
	at java.base/jdk.internal.math.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2054)
	at java.base/jdk.internal.math.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
	at java.base/java.lang.Double.parseDouble(Double.java:549)
	at net.minidev.json.parser.JSONParserBase.extractFloat(JSONParserBase.java:141)

support latest asm in accessor-smart

Currently accessor-smart depends on asm 8 which is a 1 year old release.
it should depends on 9.1 which is latest (and also to be able to use recent version other libs also based on asm)

if accessor-smart is supporting multiple asm version it should override osgi manifest as by default only asm 8 is supported

(for example by adding this instruction to maven-bundle-plugin in pom.xml)
<Import-Package>org.objectweb.asm;version="[8.0,10),*</Import-Package>

Serialize/deserialize Instant class

Hi All,

Is it possible to serialize/deserialize Instant class? The following unit-test:

import net.minidev.json.JSONValue;
import org.junit.Assert;
import org.junit.Test;

import java.time.Instant;

public class InstantTest {

    @Test
    public void test_instant() {
        Instant instant = Instant.now();

        RegularClass regularClass = new RegularClass();
        regularClass.setInstant(instant);

        String data = JSONValue.toJSONString(regularClass);
        RegularClass result = JSONValue.parse(data, RegularClass.class);

        Assert.assertEquals(result.getInstant(), instant);
    }

    public static class RegularClass {
        private Instant instant;

        public Instant getInstant() {
            return instant;
        }

        public void setInstant(Instant instant) {
            this.instant = instant;
        }
    }

}

throw exception:

java.lang.SecurityException: Prohibited package name: java.time
    at java.lang.ClassLoader.preDefineClass(ClassLoader.java:659)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:758)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:642)
    at net.minidev.asm.DynamicClassLoader.defineClass(DynamicClassLoader.java:86)
    at net.minidev.asm.BeansAccessBuilder.bulid(BeansAccessBuilder.java:313)
    at net.minidev.asm.BeansAccess.get(BeansAccess.java:111)
    at net.minidev.json.JSONValue.writeJSONString(JSONValue.java:696)
    at net.minidev.json.JSONObject.writeJSONKV(JSONObject.java:102)
    at net.minidev.json.JSONValue.writeJSONString(JSONValue.java:704)
    at net.minidev.json.JSONValue.toJSONString(JSONValue.java:746)
    at net.minidev.json.JSONValue.toJSONString(JSONValue.java:724)
    at InstantTest.test_instant(InstantTest.java:16)

Thanks

json-smart 2.0

BOM causes error message to include entire file

Normally when parsing a JSON file the message is, for example:

Unexpected token ({) at position 50

But if a byte order mark is found as the first character on the first line, the "unexpected token" that gets printed out is the entire file and the position printed is the very last position of the file.

Serializing beans without setter for a private field causes java.lang.IllegalAccessError: tried to access field

It seems like the check Accessor::isPublic is wrong since it checks if a field in a bean has a corresponding setter method. If not, the BeanAccessBuilder treats the field as public which causes IllegalAccessError when serializing the object.

It feels really weird that a setter should be required for serializing and it is a very common pattern to have immutable objects with only private fields and getters. The builder should have directed the accessor to use the getter instead in this case.

Gist with repro below:
https://gist.github.com/billybong/b0732928f5f891d67b066dc315c9b7ec

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.