-
Notifications
You must be signed in to change notification settings - Fork 20
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
Move jackson-datatype-money module from zalando #48
base: 2.19
Are you sure you want to change the base?
Conversation
@@ -0,0 +1,13 @@ | |||
//TODO how is this generated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure how this file is generated.
Is there some documentation for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be running
../mvnw moditect:generate-module-info
from new modules project dir. Let me try this on PR.
This provides the base, but must be modified; looking at other modules's module-info.java
for inspiration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmh. Alas, that command throws NPE.
1166e8e
to
f29f0e3
Compare
on-behalf-of: Zalando OSS Community Co-authored-by: Willi Schönborn <[email protected]> Co-authored-by: Philipp Hirch <[email protected]> Co-authored-by: Jörn Horstmann <[email protected]> Co-authored-by: Lauri at Zalando <[email protected]> Co-authored-by: msparer <[email protected]> Co-authored-by: Alexander Yastrebov <[email protected]> Co-authored-by: Alexey Venderov <[email protected]> Co-authored-by: Alexander Yastrebov <[email protected]> Co-authored-by: Arnaud BOIVIN <[email protected]> Co-authored-by: Bartosz Ocytko <[email protected]> Co-authored-by: Carlos Freund <[email protected]> Co-authored-by: Dario Seidl <[email protected]> Co-authored-by: Georgios Andrianakis <[email protected]> Co-authored-by: Lauri at Zalando <[email protected]> Co-authored-by: Martin Prebio <[email protected]> Co-authored-by: Sean Sullivan <[email protected]> Co-authored-by: Touko Vainio-Kaila <[email protected]> Co-authored-by: lukasniemeier-zalando <[email protected]>
f29f0e3
to
abaf36d
Compare
@cowtowncoder Please review when you have time. |
|
||
public final class CurrencyUnitDeserializerTest { | ||
|
||
private final ObjectMapper unit = new ObjectMapper().findAndRegisterModules(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is wrong: should specifically add just Money module and not whatever might happen to be in classpath. Ideally would use helper method in test base class or utility/helper class
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public final class CurrencyUnitSchemaSerializerTest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to remove or rewrite this test: it must NOT include cross-module dependency for tests because this now introduces a build/release dependency between modules.
There are ways to test schema-generation aspects (to ensure that correct schema traversal methods are called), I'd need to find examples.
Well, jackson-databind
has couple of tests under src/test/java/com/fasterxml/jackson/databind/jsonschema/
which might be helpful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok that works!
|
||
final String content = "{\"amount\":29.95}"; | ||
|
||
final JsonProcessingException exception = assertThrows( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While technically correct, use of JsonProcessingException
is not optimal as we should check specific subtype that is being thrown, JPE is the most generic Jackson exception base class.
|
||
<dependency> | ||
<groupId>org.javamoney.moneta</groupId> | ||
<artifactId>moneta-core</artifactId> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this test-only dependency? Or does module require specific Money API implementation?
import static org.apiguardian.api.API.Status.MAINTAINED; | ||
|
||
@API(status = MAINTAINED) | ||
public final class CurrencyUnitDeserializer extends JsonDeserializer<CurrencyUnit> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually should extend either StdDeserializer
or (if applicable) StdScalarDeserializer
.
import static org.apiguardian.api.API.Status.MAINTAINED; | ||
|
||
@API(status = MAINTAINED) | ||
public final class CurrencyUnitSerializer extends StdSerializer<CurrencyUnit> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly should use StdScalarSerializer
.
javax-money/pom.xml
Outdated
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.module</groupId> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per my earlier note, cannot have this dependency -- adds unwanted cross-module dependency for builds, release process.
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.kjetland</groupId> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This dependency OTOH is fine (as it's not part of Jackson module set -- and even if it had transitive dependencies to some Jackson components that'd be ok as it wouldn't complicate build/release process)
} | ||
|
||
@Override | ||
public Object deserializeWithType(final JsonParser parser, final DeserializationContext context, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If extending StdDeserializer
(or, StdScaralDeserializer
), wouldn't need to implement this method, I think.
private void checkPresent(final JsonParser parser, @Nullable final Object value, final String name) | ||
throws JsonParseException { | ||
if (value == null) { | ||
throw new JsonParseException(parser, format("Missing property: '%s'", name)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sub-optimal exception as it does not indicate value type that has the issue.
Should usually be passed DeserializationContext
and call one of methods it provides for throwing more specific (semantic) exceptions.
public void serializeWithType(final MonetaryAmount value, final JsonGenerator generator, | ||
final SerializerProvider provider, final TypeSerializer serializer) throws IOException { | ||
|
||
// effectively assuming no type information at all |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... which is basically wrong :-(
(meaning, won't work with @JsonTypeInfo
)
javax-money/src/main/java/com/fasterxml/jackson/datatype/money/MoneyModule.java
Show resolved
Hide resolved
@sri-adarsh-kumar Ok, so technically I think this looks ok (although I have suggestions and concerns wrt code actually). I think we need one or more CLAs (from https://github.com/FasterXML/jackson/ either individual or Corporate CLA):
It might be simplest to get CCLA from Zalando, although that is not a requirement if authors can give individual CLAs. |
Changed License reference (WIP) Removed cross-module dependency to jsonSchema Testing specific Modules instead of findAndRegisterModules Assert subtypes of JSONProcessingException CurrencyUnitDeserializer extends StdScalarDeserializer CurrencyUnitSerializer extends StdScalarSerializer MonetaryAmountDeserializer throws semantic exceptions using DeserializationContext MoneyModule version uses PackageVersion
d44c71e
to
487cbf9
Compare
|
||
|
||
@API(status = STABLE) | ||
public final class MoneyModule extends Module { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we actually rename this as JavaxMoneyModule
?
... also, as a side-note, is there need for "Jakarta Money module"? (wrt javax licensing resulting in "forking" of javax APIs)
@@ -0,0 +1,13 @@ | |||
//TODO how is this generated | |||
// Generated 27-Mar-2019 using Moditect maven plugin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's rewrite this comment with current date, something like "Hand-crafted 29-Oct-2024"
|
||
public final class CurrencyUnitDeserializerTest { | ||
|
||
private final ObjectMapper unit = new ObjectMapper().registerModule(new MoneyModule()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One minor request (apologies for forgetting to mention initially): let's use
JsonMapper.builder().addModule(new MoneyModule()).build();
the reason begin that ObjectMappers are immutable in Jackson 3.0, so merging this module is easier if we use builder pattern.
@sri-adarsh-kumar Thank you for updates, good job so far! The other thing then has to do with CLAs, permissions -- see my earlier note. |
Moves jackson-datatype-money module from zalando
Context
Related to #5 and zalando/jackson-datatype-money#224
From the above conversations, there is a consensus to move the zalando/jackson-datatype-money library as a sub-module of this repository.
In order to achieve this, I have moved the files almost 1:1 from the source repository.
Only major changes were related to tests. The source repo had Junit Jupiter tests with
@ParameterizedTest
. The destination library already had other tests usingjunitParams.Parameters
, so this was adopted.Review Suggestions
Please focus on