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

Move jackson-datatype-money module from zalando #48

Open
wants to merge 4 commits into
base: 2.19
Choose a base branch
from

Conversation

sri-adarsh-kumar
Copy link

@sri-adarsh-kumar sri-adarsh-kumar commented Oct 18, 2024

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 using junitParams.Parameters, so this was adopted.

Review Suggestions

Please focus on

  • How to use correct License
  • How to attribute credits correctly
  • Package naming conventions

@@ -0,0 +1,13 @@
//TODO how is this generated
Copy link
Author

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?

Copy link
Member

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.

Copy link
Member

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.

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]>
@sri-adarsh-kumar
Copy link
Author

@cowtowncoder Please review when you have time.

javax-money/pom.xml Outdated Show resolved Hide resolved

<dependency>
<groupId>org.javamoney.moneta</groupId>
<artifactId>moneta-core</artifactId>
Copy link
Member

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?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The module supports Money API implementations like moneta's FastMoney, Money and RoundedMoney.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right: I was wondering if inclusion of specific implementation was problematic wrt using something else -- but I guess one would just use Maven dependency exclude, or some other mechanism.

Or put another way: I can see such dependency necessary for testing but wasn't sure it was really needed as regular ("compile") dependency. If you think it is needed that's fine: just double-checking.

import static org.apiguardian.api.API.Status.MAINTAINED;

@API(status = MAINTAINED)
public final class CurrencyUnitDeserializer extends JsonDeserializer<CurrencyUnit> {
Copy link
Member

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> {
Copy link
Member

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 Show resolved Hide resolved
}

@Override
public Object deserializeWithType(final JsonParser parser, final DeserializationContext context,
Copy link
Member

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));
Copy link
Member

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
Copy link
Member

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)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review comment.
Do you see this as a blocker to merge this PR?

As this is not strictly related to moving the module from Zalando repo, I would prefer to treat this as a future improvement.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I don't think it is blocker: good point on "let's move it first, then improve".

@cowtowncoder
Copy link
Member

@sri-adarsh-kumar Ok, so technically I think this looks ok (although I have suggestions and concerns wrt code actually).
But one question I have is whether we need someone else's approval for contribution -- or are you the author? (I understand you work for Zalando from profile?).

I think we need one or more CLAs (from https://github.com/FasterXML/jackson/ either individual or Corporate CLA):

  1. From you (wrt directly adding files here), regardless of authorship of code
  2. Additional CLA(s) from whoever can contribute code itself (if not you).

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


@API(status = STABLE)
public final class MoneyModule extends Module {
Copy link
Member

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)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me check on this.

@cowtowncoder
Copy link
Member

@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.
If we can get that through, I should be able to merge this pr!
(getting it merged into master for 3.0 will have its challenges but one thing at a time :) )

@sri-adarsh-kumar
Copy link
Author

Thanks for all the support.
I am working on the CLA process with my organisation.


```java
ObjectMapper mapper = new ObjectMapper()
.registerModule(new MoneyModule());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's change to use new-er "addModule":

ObjectMapper mapper = JsonMapper.builder()
  .addModule(...)
  .build();


```java
ObjectMapper mapper = new ObjectMapper()
.registerModule(new MoneyModule().withQuotedDecimalNumbers());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here (addModule())

@cowtowncoder
Copy link
Member

I think code is looking almost ready for merge, so just need to deal with CLA question and it could be merged!

@cowtowncoder cowtowncoder added the cla-needed CLA needed from submitter label Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-needed CLA needed from submitter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants