lmagic233 commented on a change in pull request #14604:
URL: https://github.com/apache/flink/pull/14604#discussion_r556286139



##########
File path: 
flink-formats/flink-json/src/test/java/org/apache/flink/formats/json/JsonRowDataSerDeSchemaTest.java
##########
@@ -562,6 +579,56 @@ public void testSerializationMapNullKey() throws Exception 
{
         assertEquals(expectResult3, new String(actual3));
     }
 
+    @Test
+    public void testSerializationDecimalEncode() throws Exception {
+        BigDecimal decimal1 = new BigDecimal("123.456789");
+        BigDecimal decimal2 = new BigDecimal("454621864049246170");
+        BigDecimal decimal3 = new BigDecimal("0.000000027");
+
+        ObjectMapper objectMapper = new ObjectMapper();
+        
objectMapper.configure(JsonGenerator.Feature.WRITE_BIGDECIMAL_AS_PLAIN, true);
+
+        ObjectNode root = objectMapper.createObjectNode();
+        root.put("decimal1", decimal1);
+        root.put("decimal2", decimal2);
+        root.put("decimal3", decimal3);
+
+        byte[] serializedJson = objectMapper.writeValueAsBytes(root);
+
+        DataType dataType =
+                ROW(
+                        FIELD("decimal1", DECIMAL(9, 6)),
+                        FIELD("decimal2", DECIMAL(20, 0)),
+                        FIELD("decimal3", DECIMAL(11, 9)));
+
+        RowType schema = (RowType) dataType.getLogicalType();
+        TypeInformation<RowData> resultTypeInfo = InternalTypeInfo.of(schema);
+
+        JsonRowDataDeserializationSchema deserializationSchema =
+                new JsonRowDataDeserializationSchema(
+                        schema, resultTypeInfo, false, false, 
TimestampFormat.ISO_8601);
+
+        Row expected = new Row(3);
+        expected.setField(0, decimal1);
+        expected.setField(1, decimal2);
+        expected.setField(2, decimal3);
+
+        RowData rowData = deserializationSchema.deserialize(serializedJson);

Review comment:
       Ditto.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to