{"action":"created","issue":{"url":"https://api.github.com/repos/gzoller/ScalaJack/issues/66","repository_url":"https://api.github.com/repos/gzoller/ScalaJack","labels_url":"https://api.github.com/repos/gzoller/ScalaJack/issues/66/labels{/name}","comments_url":"https://api.github.com/repos/gzoller/ScalaJack/issues/66/comments","events_url":"https://api.github.com/repos/gzoller/ScalaJack/issues/66/events","html_url":"https://github.com/gzoller/ScalaJack/issues/66","id":169981239,"number":66,"title":"Custom renderings for Java objects do not work with MongoFlavor()","user":{"login":"tksmrch","id":2744488,"avatar_url":"https://avatars.githubusercontent.com/u/2744488?v=3","gravatar_id":"","url":"https://api.github.com/users/tksmrch","html_url":"https://github.com/tksmrch","followers_url":"https://api.github.com/users/tksmrch/followers","following_url":"https://api.github.com/users/tksmrch/following{/other_user}","gists_url":"https://api.github.com/users/tksmrch/gists{/gist_id}","starred_url":"https://api.github.com/users/tksmrch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tksmrch/subscriptions","organizations_url":"https://api.github.com/users/tksmrch/orgs","repos_url":"https://api.github.com/users/tksmrch/repos","events_url":"https://api.github.com/users/tksmrch/events{/privacy}","received_events_url":"https://api.github.com/users/tksmrch/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-08-08T17:39:30Z","updated_at":"2016-08-10T19:33:17Z","closed_at":null,"body":"Hi gzoller, \r\n\r\nThis is such an awesome product. I really like the simple, intuitive interface and the easy integration with MongoDB. My team just started to experiment with ScalaJack in the hope that ScalaJack will greatly simplify our code related to object persistency . \r\n\r\nWe just ran into an issue with custom renderings of Java classes using VistorContext. We are able to render a Java class with the default Jack flavor while using MongoFlavor. \r\n\r\nI'd highly appreciate if you could give us any thoughts around this. \r\n\r\nBest regards, \r\n\r\n\r\nException in thread \"main\" scala.MatchError: JavaType(com.instinet.gtr.exchange.ExchangeId) (of class co.blocke.scalajack.JavaType)\r\n\tat co.blocke.scalajack.mongo.MongoJackFlavor$MongoReadRenderer.co$blocke$scalajack$mongo$MongoJackFlavor$MongoReadRenderer$$_render(MongoFlavor.scala:232)\r\n\tat co.blocke.scalajack.mongo.MongoJackFlavor$MongoReadRenderer.render(MongoFlavor.scala:38)\r\n\tat co.blocke.scalajack.mongo.MongoJackFlavor$MongoReadRenderer.render(MongoFlavor.scala:33)\r\n\tat co.blocke.scalajack.ScalaJack$class.render(ScalaJack.scala:30)\r\n\tat co.blocke.scalajack.mongo.MongoFlavor$MongoScalaJack.render(MongoFlavor.scala:28)\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/gzoller/ScalaJack/issues/comments/238978447","html_url":"https://github.com/gzoller/ScalaJack/issues/66#issuecomment-238978447","issue_url":"https://api.github.com/repos/gzoller/ScalaJack/issues/66","id":238978447,"user":{"login":"tksmrch","id":2744488,"avatar_url":"https://avatars.githubusercontent.com/u/2744488?v=3","gravatar_id":"","url":"https://api.github.com/users/tksmrch","html_url":"https://github.com/tksmrch","followers_url":"https://api.github.com/users/tksmrch/followers","following_url":"https://api.github.com/users/tksmrch/following{/other_user}","gists_url":"https://api.github.com/users/tksmrch/gists{/gist_id}","starred_url":"https://api.github.com/users/tksmrch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tksmrch/subscriptions","organizations_url":"https://api.github.com/users/tksmrch/orgs","repos_url":"https://api.github.com/users/tksmrch/repos","events_url":"https://api.github.com/users/tksmrch/events{/privacy}","received_events_url":"https://api.github.com/users/tksmrch/received_events","type":"User","site_admin":false},"created_at":"2016-08-10T19:33:17Z","updated_at":"2016-08-10T19:33:17Z","body":"Hi Greg, \r\n\r\nThanks for your reply. And yes, JSON rendering is working while I want to use Mongo rendering which isn't working. Additionally, I can't convert JSON string back into a Java object using the default flavor, either. \r\n\r\nI'm using ScalaJack 4.8.3 with Java 8.  \r\n\r\nI'm pasting my sample code here. Although I'm not sure if my Java class fits the definition of a \"value class,\" it requires only one value (int) to instantiate the class. \r\n\r\n`\r\n// Java value class\r\npublic class MyJavaDate\r\n{\r\n    private final int year;\r\n    private final int month;\r\n    private final int day;\r\n\r\n    public MyJavaDate(int year, int month, int day) {\r\n        this.year = year;\r\n        this.month = month;\r\n        this.day = day;\r\n    }\r\n\r\n    public int toYYYYMMDD() {\r\n        return year * 10000 + month * 100 + day;\r\n    }\r\n\r\n    public static MyJavaDate fromYYYYMMDD(int yyyymmdd) {\r\n        int year  = yyyymmdd / 10000;\r\n        int month = (yyyymmdd - year * 10000) / 100;\r\n        int day   = yyyymmdd - year * 10000 - month * 100;\r\n\r\n        return new MyJavaDate(year, month, day);\r\n    }\r\n}\r\n\r\n\r\n// Scala app\r\nobject ScalaJackCustomHandler extends App\r\n{\r\n  val MyJavaDateHandler = CustomReadRender(\r\n    {\r\n      case (j:JsonKind, yyyymmdd:Int) => MyJavaDate.fromYYYYMMDD(yyyymmdd)\r\n    },\r\n    {\r\n      case (j:JsonKind, date:MyJavaDate) => date.toYYYYMMDD\r\n    }\r\n  )\r\n\r\n  val HandlerMap = Map(\r\n    \"com.instinet.gtr.research.mongo.tutorial.data.MyJavaDate\" ->  MyJavaDateHandler\r\n  )\r\n\r\n  val vc = VisitorContext().copy(customHandlers = HandlerMap)\r\n\r\n  val date = new MyJavaDate(2016, 8, 10)\r\n\r\n  val sjPlain  = ScalaJack()\r\n  val sjMongo  = ScalaJack(MongoFlavor())\r\n\r\n\r\n  //--- Serialization\r\n  val dateJson = sjPlain.render(date, vc)\r\n  println(dateJson)                       // => 20160810\r\n\r\n  val dateDoc = sjMongo.render(date, vc)  // Error\r\n  println(dateDoc)\r\n\r\n  //--- Deserialization\r\n  sjPlain.read[MyJavaDate](dateJson)      // Error\r\n}\r\n`"}}
{"actor":{"display_login":"tksmrch"}}