Skip to content

Inconsistences in array output types between JsonSmartJsonProvider and JacksonJsonProvider when parsing json #1061

@ArtemMarchukQlikCom

Description

@ArtemMarchukQlikCom

JsonSmartJsonProvider and JacksonJsonProvider have different array creation logic:

https://github.com/json-path/JsonPath/blob/master/json-path/src/main/java/com/jayway/jsonpath/spi/json/JsonSmartJsonProvider.java#L53
https://github.com/json-path/JsonPath/blob/master/json-path/src/main/java/com/jayway/jsonpath/spi/json/JacksonJsonProvider.java#L113

This cases output format changings on json parsing.
For example in we use the following code we will see different output.
`package com.example;

import com.jayway.jsonpath.*;
import com.jayway.jsonpath.spi.json.JacksonJsonProvider;
import com.jayway.jsonpath.spi.json.JsonSmartJsonProvider;

public class Demo {

public static void main(String[] args) throws Exception {
    String json = "{\"Request\": \"12345\",\"ERR\":[{\"field\":\"ADD\",\"keyword\":\"MustHaveAdd\",\"entity\":\"TEST\"}]}";

    Configuration configuration1 = Configuration.builder()
            .jsonProvider(new JsonSmartJsonProvider())
            .build();

    Configuration configuration2 = Configuration.builder()
            .jsonProvider(new JacksonJsonProvider())
            .build();


    Object parced1 = JsonPath.using(configuration1).parse(json).read("$.ERR[*]", new Predicate[0]);
    Object parced2 = JsonPath.using(configuration2).parse(json).read("$.ERR[*]", new Predicate[0]);

    System.out.println(parced1); //JsonSmartJsonProvider
    System.out.println(parced2); //JacksonJsonProvider
}

}
Console output:[{"field":"ADD","keyword":"MustHaveAdd","entity":"TEST"}]
[{field=ADD, keyword=MustHaveAdd, entity=TEST}]`

Is it possible to make some unique array output type for all providers?
Now we use the following fix ArtemMarchukQlikCom@7ac8104
to set the same output in JacksonJsonProvider as it was in JsonSmartJsonProvider

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions