|
167 | 167 | import com.fasterxml.jackson.databind.exc.InvalidDefinitionException;
|
168 | 168 | import com.fasterxml.jackson.databind.exc.InvalidFormatException;
|
169 | 169 | import com.fasterxml.jackson.databind.exc.InvalidTypeIdException;
|
170 |
| -import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException; |
171 | 170 |
|
172 | 171 | /**
|
173 | 172 | * Various test cases serializing and deserializing Scout data objects from/to JSON
|
@@ -1803,6 +1802,24 @@ public void testSerializeDeserialize_EntityWithCollectionRaw() throws Exception
|
1803 | 1802 | assertEquals("TestItem2", attribute7.get(1).get(ScoutDataObjectModule.DEFAULT_TYPE_ATTRIBUTE_NAME));
|
1804 | 1803 | }
|
1805 | 1804 |
|
| 1805 | + @Test |
| 1806 | + public void testSerializeDeserialize_RawEntityWithDouble() throws Exception { |
| 1807 | + DoEntity entity = BEANS.get(DoEntity.class); |
| 1808 | + entity.put("attribute", 45.69); |
| 1809 | + String json = s_dataObjectMapper.writeValueAsString(entity); |
| 1810 | + DoEntity doMarshalled = s_dataObjectMapper.readValue(json, DoEntity.class); |
| 1811 | + assertEquals(new BigDecimal("45.69"), doMarshalled.get("attribute")); |
| 1812 | + } |
| 1813 | + |
| 1814 | + @Test |
| 1815 | + public void testSerializeDeserialize_RawEntityWithDoubleList() throws Exception { |
| 1816 | + DoEntity entity = BEANS.get(DoEntity.class); |
| 1817 | + entity.put("attribute", List.of(45.69)); |
| 1818 | + String json = s_dataObjectMapper.writeValueAsString(entity); |
| 1819 | + DoEntity doMarshalled = s_dataObjectMapper.readValue(json, DoEntity.class); |
| 1820 | + assertEquals(new BigDecimal("45.69"), doMarshalled.getList("attribute").get(0)); |
| 1821 | + } |
| 1822 | + |
1806 | 1823 | @Test
|
1807 | 1824 | public void testSerializeDeserialize_TestMapDo() throws Exception {
|
1808 | 1825 | TestMapDo mapDo = new TestMapDo();
|
@@ -3225,27 +3242,28 @@ public void testSerializeDeserializeThrowable() throws Exception {
|
3225 | 3242 | assertArrayEquals(exception.getStackTrace(), marshalled.getException().getStackTrace());
|
3226 | 3243 | }
|
3227 | 3244 |
|
| 3245 | + /** |
| 3246 | + * {@link Optional} is currently not serializable/deserializable using Scout Jackson implementation. |
| 3247 | + */ |
3228 | 3248 | @Test
|
3229 | 3249 | public void testSerializeDeserializeOptionalDo() throws Exception {
|
3230 | 3250 | @SuppressWarnings("unchecked")
|
3231 | 3251 | TestOptionalDo optional = BEANS.get(TestOptionalDo.class)
|
3232 | 3252 | .withOptString(Optional.empty())
|
3233 | 3253 | .withOptStringList(Optional.empty(), Optional.of("foo"));
|
3234 |
| - String json = s_dataObjectMapper.writeValueAsString(optional); |
3235 | 3254 |
|
3236 |
| - // currently serializable using Scout Jackson implementation, but without values, e.g. useless! |
3237 |
| - assertJsonEquals("TestOptionalDo.json", json); |
| 3255 | + // Expect: |
| 3256 | + // com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Java 8 optional type `java.util.Optional<java.lang.String>` |
| 3257 | + // not supported by default: add Module "com.fasterxml.jackson.datatype:jackson-datatype-jdk8" to enable handling |
| 3258 | + JsonMappingException writeException = assertThrows(JsonMappingException.class, () -> s_dataObjectMapper.writeValueAsString(optional)); |
| 3259 | + assertTrue("expected InvalidDefinitionException, got " + writeException, writeException instanceof InvalidDefinitionException); |
3238 | 3260 |
|
3239 |
| - // currently not deserializable using Scout Jackson implementation |
| 3261 | + // Expect: |
| 3262 | + // com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Java 8 optional type `java.util.Optional<java.lang.String>` |
| 3263 | + // not supported by default: add Module "com.fasterxml.jackson.datatype:jackson-datatype-jdk8" to enable handling |
| 3264 | + String json = readResourceAsString("TestOptionalDo.json"); |
3240 | 3265 | JsonMappingException exception = assertThrows(JsonMappingException.class, () -> s_dataObjectMapper.readValue(json, TestOptionalDo.class));
|
3241 |
| - |
3242 |
| - // TODO [23.1] pbz remove when JDK 11 is no longer supported |
3243 |
| - if ("11".equals(System.getProperty("java.specification.version"))) { |
3244 |
| - assertTrue("expected cause UnrecognizedPropertyException, got " + exception.getCause(), exception.getCause() instanceof UnrecognizedPropertyException); |
3245 |
| - } |
3246 |
| - else { |
3247 |
| - assertTrue("expected cause InvalidDefinitionException, got " + exception.getCause(), exception.getCause() instanceof InvalidDefinitionException); |
3248 |
| - } |
| 3266 | + assertTrue("expected InvalidDefinitionException, got " + exception.getCause(), exception.getCause() instanceof InvalidDefinitionException); |
3249 | 3267 | }
|
3250 | 3268 |
|
3251 | 3269 | @Test
|
|
0 commit comments