Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Serialization should work on all levels and allow "super- generics"? #58

Open
jansupol opened this issue Oct 5, 2017 · 3 comments

Comments

@jansupol
Copy link
Owner

jansupol commented Oct 5, 2017

Custom Serialization currently doesn't seem to trigger for anything other than the initial object passed into "toJson", should this be the case? I want to serialize every instance of X in a specific way, but this doesn't seem possible at the moment. This could be a new property "DEEP_CUSTOM_SERIALIZATION"

Also should JsonbSerializer<Object> allow me to add custom serialization for every object passed into "toJson" ?

@jansupol
Copy link
Owner Author

@m0mus Commented
Please be more specific in your request. Sample code would be nice to have for better understanding. :)

@jansupol
Copy link
Owner Author

@Shaunwild97 Commented

JsonbBuilder
		.newBuilder()
		.withConfig( new JsonbConfig()
			.setProperty( DEEP_CUSTOM_SERIALIZATION, true ) )
		.build();

public class EmptyListSerializer implements JsonbSerializer<Collection>
{
	@Override
	public void serialize( Collection collection, JsonGenerator jg, SerializationContext sc )
	{
		if ( collection == null )
		{
			return;
		}

		if ( collection.isEmpty() )
		{
			sc.serialize( null, jg );
		}
		else
		{
			sc.serialize( collection, jg );
		}
	}
}

With the above code snippets, If I serialized a class which had multiple Collections in it, they would all trigger the custom serializer. With DEEP_CUSTOM_SERIALIZATION set to false, only the top level Collection would trigger the custom serialization (this is what happens currently by default)

My second point was referring to A JsonbSerializer with generic type <Object> that would work for every object. The generic type in JsonbSerializer should be the superclass of the object, not the object itself.

@jansupol
Copy link
Owner Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant