[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
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

JaversException MANAGED_CLASS_MAPPING_ERROR: given javaClass '...' is mapped to PrimitiveType, expected ManagedType #1285

Open
MaxiBerdy opened this issue Apr 17, 2023 · 1 comment

Comments

@MaxiBerdy
Copy link

Hi, I use Javers in my work to compare java objects and collections, for example in unit test to give a hint on why two objects have some differences. I came across this exception, when I tried to use an interface instead of an enum type in one of my objects.

JaversException MANAGED_CLASS_MAPPING_ERROR: given javaClass 'class com.somepackage.JaversManagedTypeIssueTest$MyFirstEnum' is mapped to PrimitiveType, expected ManagedType

I created a test case using Junit (sorry if this is not written in groovy, I hope this is okay)

import org.javers.core.Javers;
import org.javers.core.JaversBuilder;
import org.javers.core.diff.Diff;
import org.junit.Test;

public class JaversManagedTypeIssueTest {
	private static final Javers javers = JaversBuilder.javers().build();

	interface MyEnumInterface {
	}

	enum MyFirstEnum implements MyEnumInterface {
		FIRST, FIRST_THINGS_FIRST
	}

	enum MySecondEnum implements MyEnumInterface {
		SECOND, ON_THE_SECOND_HAND
	}

	static class MyObject {
		MyEnumInterface objectEnum;

		public MyObject(final MyEnumInterface objectEnum) {
			this.objectEnum = objectEnum;
		}
	}

	@Test()
	public void testIssue() {
		final MyObject myObjectWithFirst = new MyObject(MyFirstEnum.FIRST);
		final MyObject myObjectWithSecond = new MyObject(MySecondEnum.ON_THE_SECOND_HAND);

		final Diff diff = javers.compare(myObjectWithFirst, myObjectWithSecond); // This triggers the exception

		assert diff.hasChanges();
	}
}

Do you know if this is an intended behaviour ? I don't know much on the inner working of Javers, I was hoping it would handle the interface with the different enum instances, and try to compare the values when possible.
Thanks in advance for your help

@bartoszwalacik
Copy link
Member
bartoszwalacik commented May 17, 2023

Hi @MaxiBerdy , please provide a PR with a failing test case, see instructions here.
From what I see, you are using quite uncommon approach of having an enum extending an empty interface. I guess Javers might not support it

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

2 participants