Reflection based serialization of not owned field types
Avatah opened this issue · 5 comments
Hello.
I'd like to use reflection based serialization but my objects have fields of type java.util.UUID.
I can't add @BeanInfo annotation and modify this type because it's a library type.
I'm able to define Format for class UUID to serialize uuid.toString and deserialize UUID.fromString() but how to use it in reflection based serializer?
I think that JsBean methods: fromJSON and toJSON should take into account some implicit formats that may be defined.
In other words:
I'd like to mix reflection based serialization with typeclass based.
Hi - Thanks for your interest in sjson. It will help a lot, if you provide me a failing test case. I can then take it up and try to help you with something.
abstract class Parent{
var uuid: UUID
}
case class Event(name: String) extends Parent
I'd like to serialize Event objects so that:
- uuid would be serialized as string (uuid.toString) and deserialized by UUID.fromString
- There should be a possibility of serializing any case class that extends Parent
- Serialized case classes should not contain any mapping data (only @BeanInfo annotation is permitted)
Thank you. Let me think through over the weekend. Hopefully we can find out some solution :)
Looks like it's getting difficult to come up with a generic API for toJSON and fromJSON which combines both reflection based and type class based serialization. This is because for any object, part of it may be done using reflection based while the other part may be type class based. Consider if UUID of your example is contained as part of a larger object (which u do by inheritance). I would recommend using type class based serialization for all these cases. The entire purpose of reflection based serialization was to handle not-so-complex use cases in a simplistic way. For complex use cases the type class based approach is recommended.