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

Serializer not called on List Elements #614

Open
mdoy179 opened this issue Sep 13, 2023 · 2 comments
Open

Serializer not called on List Elements #614

mdoy179 opened this issue Sep 13, 2023 · 2 comments
Labels
bug Something isn't working right

Comments

@mdoy179
Copy link

mdoy179 commented Sep 13, 2023

Describe the bug
In version 3.0.3 of yasson, the elements of a list do not have their Serializers called. This issue does not happen in version 2.0.4.

In the following example, if a List<Temp> is serialized, the serializer will not throw the exception (or be called). If Temp is serialized by itself, the serializer will be called.:

@JsonbTypeSerializer(Temp.Serializer.class)
public class Temp {

    private List<UUID> vals;

    public List<UUID> getVals() {
        return vals;
    }

    public Temp(List<UUID> vals) {
        this.vals = vals;
    }

    public static class Serializer implements JsonbSerializer<Temp> {

        @Override
        public void serialize(Temp obj, JsonGenerator generator, SerializationContext ctx) {
            throw new UnsupportedOperationException("Unimplemented method 'serialize'");
        }

    }

}

To Reproduce
Included sample app with unit tests to replicate the problem.
yasson-bug-sample.zip

Expected behavior
Expected that a list would be serialized.

System information:

  • OS: Windows
  • Java Version: 17
  • Yasson Version: 3.0.3

Additional context
N/A

@mdoy179 mdoy179 added the bug Something isn't working right label Sep 13, 2023
@mdoy179
Copy link
Author

mdoy179 commented Sep 18, 2023

This issue seems related to this issue that was closed: #587. I'm wondering if serialization was not fixed?

@mdoy179
Copy link
Author

mdoy179 commented Sep 19, 2023

Was able to get a workaround working by using jsonbConfig. If you update the ExampleTests.java to pass in a jsonbConfig then it will work. Something like this:

    @BeforeEach
    void setup() {
        myClass = new MyClass("test");
        JsonbConfig jsonbConfig = new JsonbConfig();
        
        var serializer = new JsonbSerializer[]{
            new MyClass.Serializer()
        };
        jsonbConfig.withSerializers(serializer);
        
        jsonb = JsonbBuilder.create(jsonbConfig);
    }  

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working right
Projects
None yet
Development

No branches or pull requests

1 participant