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

Using sameBeanAs() with org.javamoney.moneta.Money leads to UnsopportedOperationException #20

Open
ChristianBusch opened this issue Aug 28, 2016 · 4 comments

Comments

@ChristianBusch
Copy link

When trying to compare 2 objects containing an instance of org.javamoney.moneta.Money shazamcrest / GSON will throw

java.lang.UnsupportedOperationException: Attempted to serialize java.lang.Class: org.javamoney.moneta.Money. Forgot to register a type adapter?

The stack trace beginning just after the test class: shazamcrestStackTrace.txt

Do I need to augment my code to make this work or is this an actual bug in shazamcrest / GSON / moneta? From the shazamcrest doc it looks like it should work with any class.

Minimal code to reproduce:

assertThat(Money.of(42, "EUR"), sameBeanAs(Money.of(42, "EUR")));

Many thanks in advance for your help.
Christian

@TWiStErRob
Copy link

Problem looks similar to #14 in that this type needs custom serialized (ignoring after serialization is not viable here). Money.monetaryContext is being serialized, which contains a Class<?> typed field, which GSON doesn't like.

Mainainers, what do you think about adding a type adapter for Class that calls getName()/fromClass?

@roloreaper
Copy link

Other options is to add the ability to add Custom Type to the GSON Instance.
Allowing the person to modify how certain objects render to add the readablitiy of test output!

@TWiStErRob
Copy link

@roloreaper I think that's out of the question because the fact that it uses GSON is an implementation detail, though it could be hidden behind a nice wrapper API to be able to customize things.

@roloreaper
Copy link

Ok will see what the native java interface are for JSon

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

3 participants