You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Doug Cutting (Jira)" <ji...@apache.org> on 2020/04/09 16:43:00 UTC

[jira] [Commented] (AVRO-2775) JacksonUtils: exception when calling toJsonNode()

    [ https://issues.apache.org/jira/browse/AVRO-2775?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17079561#comment-17079561 ] 

Doug Cutting commented on AVRO-2775:
------------------------------------

The only downside I can see is that for applications that only intend to use the types listed in [JsonProperties|https://avro.apache.org/docs/current/api/java/org/apache/avro/JsonProperties.html], changing this would permit them to include arbitrary Java data structures, which might obscure a bug if this was not intended.  Are there other compatibility risks to adding this functionality?

> JacksonUtils: exception when calling toJsonNode() 
> --------------------------------------------------
>
>                 Key: AVRO-2775
>                 URL: https://issues.apache.org/jira/browse/AVRO-2775
>             Project: Apache Avro
>          Issue Type: Bug
>          Components: java
>    Affects Versions: 1.9.2
>            Reporter: Andy Le
>            Priority: Major
>
> I've got a simple test as followed
> {code:java}
> public class TestJacksonUtils {
>   public static class Age{
>     public int value = 9;
>   }
>   @Test
>   public void testToJson(){
>     Map<String, Object> kv = new HashMap<>();
>     kv.put("age", 9);
>     JsonNode node1 = JacksonUtils.toJsonNode(kv); // -> This is OK
>     Object obj = new Age();
>     JsonNode node2 = JacksonUtils.toJsonNode(obj); // -> This will trigger an exception
>   }
> }
> {code}
> When I ran the test:
> {noformat}
> org.apache.avro.AvroRuntimeException: Unknown datum class: class org.apache.avro.util.internal.TestJacksonUtils$Age
> 	at org.apache.avro.util.internal.JacksonUtils.toJson(JacksonUtils.java:87)
> 	at org.apache.avro.util.internal.JacksonUtils.toJsonNode(JacksonUtils.java:48)
> 	at org.apache.avro.util.internal.TestJacksonUtils.testToJson(TestJacksonUtils.java:20)
> {noformat}
> I've read the code & tests for JacksonUtils. Instead of raising exceptions at [line #87|https://github.com/apache/avro/blob/master/lang/java/avro/src/main/java/org/apache/avro/util/internal/JacksonUtils.java#L87], I see we can auto convert objects into maps, every thing's gonna fine.
> My question is:
> - Is raising exception acceptable?
> - Any other way to have `toJsonNode` for general objects?



--
This message was sent by Atlassian Jira
(v8.3.4#803005)