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

Ryan Skraba commented on AVRO-2775:
-----------------------------------

Hello!  Just a quick point of view on this -- if I understand correctly, the 
goal is to be able to pass a POJO (that Jackson can handle) as a property 
(metadata) value in a schema?

The code that would be exposed to the user would be something like this:

{code}
  Schema s = ...
  s.addProp("age", new Age(9));
  ...
  // later
  Map m = (Map) s.getObjectProp("age")
{code}

I don't see this being a great idea, as opposed to the current behaviour, which 
is to only support a specified list of permitted java types, and throw an 
exception otherwise.  

My reasoning is: 

# Turning a  POJO into JSON is Jackson-specific behaviour and I'm not sure we 
want to tie Avro behaviour to it.  It might not be a big deal (if we're not 
planning on replacing Jackson any time soon).  
# Currently, what we put into a property value is also what we'll get out... 
and I think will always be the expected behaviour for the user!

If we maintain the current behaviour, the user is responsible for turning the 
POJO {{Age}} into the permitted java types, which seems reasonable to me.

> 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)

Reply via email to