-
Notifications
You must be signed in to change notification settings - Fork 37
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
Serialising Either: IncompatibleClassChangeError #174
Comments
Hi @mcac0006 , thanks for reporting this. It sounds like a bug. On my side, I tried to reproduce it but without success. Could you provide more detail, such as the version of Vavr-Jackson, the version of Jackson, the source code of Here is the my attempt but both tests passed, using the last commit 0538bdb on package io.vavr.jackson.issues;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.vavr.control.Either;
import io.vavr.jackson.datatype.VavrModule;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
class Issue174Test {
@Test
void eitherLeft() throws Exception {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(new VavrModule());
Cat cat = new Cat();
cat.name = "Bianca";
Either<Cat, Dog> either = Either.left(cat);
String json = objectMapper.writeValueAsString(either);
assertEquals("[\"left\",{\"name\":\"Bianca\"}]", json);
Either<Cat, Dog> restored = objectMapper.readValue(json, new TypeReference<Either<Cat, Dog>>() {});
assertEquals("Bianca", restored.getLeft().name);
}
@Test
void eitherRight() throws Exception {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(new VavrModule());
Dog dog = new Dog();
dog.name = "Labrador";
Either<Cat, Dog> either = Either.right(dog);
String json = objectMapper.writeValueAsString(either);
assertEquals("[\"right\",{\"name\":\"Labrador\"}]", json);
Either<Cat, Dog> restored = objectMapper.readValue(json, new TypeReference<Either<Cat, Dog>>() {});
assertEquals("Labrador", restored.get().name);
}
static class Cat {
@JsonProperty("name")
String name;
}
static class Dog {
@JsonProperty("name")
String name;
}
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Some observations:
io.vavr.jackson.datatype.serialize.EitherSerializer#serialize
's own value parameter is just fine through debug watch.Unless I am missing something, I think it may be a generics issue/type erasure in
EitherSerializer
(Either.One<Cat>
is technically not a direct subtype ofEither<?, ?>
).The text was updated successfully, but these errors were encountered: