Skip to content

Commit

Permalink
Failing test case demonstrating issue
Browse files Browse the repository at this point in the history
  • Loading branch information
knservis committed Feb 16, 2018
1 parent 6c738c9 commit e8d54c4
Showing 1 changed file with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.jayway.jsonpath.spi.json.JacksonJsonNodeJsonProvider;
import com.jayway.jsonpath.spi.mapper.JacksonMappingProvider;
import com.jayway.jsonpath.spi.mapper.MappingException;
import org.junit.Test;

Expand Down Expand Up @@ -122,6 +126,32 @@ public void setPropertyWithPOJO() {
String id = context.read("$.data.id", String.class);
assertThat(id).isEqualTo(uuid.toString());
}

@Test
public void mapPropertyWithPOJO() {
String someJson = "" +
"{\n" +
" \"a\": \"a\",\n" +
" \"b\": \"b\"\n" +
"}";
ObjectMapper om = new ObjectMapper();
om.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
Configuration c = Configuration
.builder()
.mappingProvider(new JacksonMappingProvider())
.jsonProvider(new JacksonJsonNodeJsonProvider(om))
.build();
DocumentContext context = JsonPath.using(c).parse(someJson);
String someJsonStr = context.jsonString();
DocumentContext altered = context.map("$['a', 'b', 'c']", new MapFunction() {
@Override
public Object map(Object currentValue, Configuration configuration) {
return currentValue;
}
});
assertThat(altered.jsonString()).isEqualTo(someJsonStr);
}

// https://github.com/json-path/JsonPath/issues/366
public void empty_array_check_works() throws IOException {
String json = "[" +
Expand Down

0 comments on commit e8d54c4

Please sign in to comment.