|
1 | 1 | package com.jayway.jsonpath; |
2 | 2 |
|
| 3 | +import com.fasterxml.jackson.annotation.JsonCreator; |
| 4 | +import com.fasterxml.jackson.annotation.JsonProperty; |
3 | 5 | import com.fasterxml.jackson.databind.JsonNode; |
4 | 6 | import com.fasterxml.jackson.databind.node.ArrayNode; |
5 | 7 | import com.fasterxml.jackson.databind.node.JsonNodeFactory; |
|
9 | 11 |
|
10 | 12 | import java.io.IOException; |
11 | 13 | import java.util.List; |
| 14 | +import java.util.UUID; |
12 | 15 |
|
13 | 16 | import static com.jayway.jsonpath.JsonPath.using; |
14 | 17 | import static org.assertj.core.api.Assertions.assertThat; |
@@ -111,6 +114,14 @@ public void test_type_ref_fail() throws IOException { |
111 | 114 | } |
112 | 115 |
|
113 | 116 | @Test |
| 117 | + // https://github.com/json-path/JsonPath/issues/364 |
| 118 | + public void setPropertyWithPOJO() { |
| 119 | + DocumentContext context = JsonPath.using(JACKSON_JSON_NODE_CONFIGURATION).parse("{}"); |
| 120 | + UUID uuid = UUID.randomUUID(); |
| 121 | + context.put("$", "data", new Data(uuid)); |
| 122 | + String id = context.read("$.data.id", String.class); |
| 123 | + assertThat(id).isEqualTo(uuid.toString()); |
| 124 | + } |
114 | 125 | // https://github.com/json-path/JsonPath/issues/366 |
115 | 126 | public void empty_array_check_works() throws IOException { |
116 | 127 | String json = "[" + |
@@ -150,5 +161,15 @@ public static class FooBarBaz<T> { |
150 | 161 | public static class Gen { |
151 | 162 | public String eric; |
152 | 163 | } |
| 164 | + |
| 165 | + public static final class Data { |
| 166 | + @JsonProperty("id") |
| 167 | + UUID id; |
| 168 | + |
| 169 | + @JsonCreator |
| 170 | + Data(@JsonProperty("id") final UUID id) { |
| 171 | + this.id = id; |
| 172 | + } |
| 173 | + } |
153 | 174 |
|
154 | 175 | } |
0 commit comments