• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

zalando / jackson-datatype-money / #2246

pending completion
#2246

push

web-flow
Bump maven-compiler-plugin from 3.10.1 to 3.11.0 (#437)

Bumps [maven-compiler-plugin](https://github.com/apache/maven-compiler-plugin) from 3.10.1 to 3.11.0.
- [Release notes](https://github.com/apache/maven-compiler-plugin/releases)
- [Commits](https://github.com/apache/maven-compiler-plugin/compare/maven-compiler-plugin-3.10.1...maven-compiler-plugin-3.11.0)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-compiler-plugin
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

142 of 142 relevant lines covered (100.0%)

1.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/main/java/org/zalando/jackson/datatype/money/MonetaryAmountDeserializer.java
1
package org.zalando.jackson.datatype.money;
2

3
import com.fasterxml.jackson.core.JsonParseException;
4
import com.fasterxml.jackson.core.JsonParser;
5
import com.fasterxml.jackson.core.JsonToken;
6
import com.fasterxml.jackson.databind.DeserializationContext;
7
import com.fasterxml.jackson.databind.JsonDeserializer;
8
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException;
9
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
10

11
import javax.annotation.Nullable;
12
import javax.money.CurrencyUnit;
13
import javax.money.MonetaryAmount;
14
import java.io.IOException;
15
import java.math.BigDecimal;
16
import java.util.Arrays;
17

18
import static com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES;
19
import static java.lang.String.format;
20

21
final class MonetaryAmountDeserializer<M extends MonetaryAmount> extends JsonDeserializer<M> {
22

23
    private final MonetaryAmountFactory<M> factory;
24
    private final FieldNames names;
25

26
    MonetaryAmountDeserializer(final MonetaryAmountFactory<M> factory, final FieldNames names) {
1✔
27
        this.factory = factory;
1✔
28
        this.names = names;
1✔
29
    }
1✔
30

31
    @Override
32
    public Object deserializeWithType(final JsonParser parser, final DeserializationContext context,
33
            final TypeDeserializer deserializer) throws IOException {
34

35
        // effectively assuming no type information at all
36
        return deserialize(parser, context);
1✔
37
    }
38

39
    @Override
40
    public M deserialize(final JsonParser parser, final DeserializationContext context) throws IOException {
41
        BigDecimal amount = null;
1✔
42
        CurrencyUnit currency = null;
1✔
43

44
        while (parser.nextToken() != JsonToken.END_OBJECT) {
1✔
45
            final String field = parser.getCurrentName();
1✔
46

47
            parser.nextToken();
1✔
48

49
            if (field.equals(names.getAmount())) {
1✔
50
                amount = context.readValue(parser, BigDecimal.class);
1✔
51
            } else if (field.equals(names.getCurrency())) {
1✔
52
                currency = context.readValue(parser, CurrencyUnit.class);
1✔
53
            } else if (field.equals(names.getFormatted())) {
1✔
54
                //noinspection UnnecessaryContinue
55
                continue;
1✔
56
            } else if (context.isEnabled(FAIL_ON_UNKNOWN_PROPERTIES)) {
1✔
57
                throw UnrecognizedPropertyException.from(parser, MonetaryAmount.class, field,
1✔
58
                        Arrays.asList(names.getAmount(), names.getCurrency(), names.getFormatted()));
1✔
59
            } else {
60
                parser.skipChildren();
1✔
61
            }
62
        }
1✔
63

64
        checkPresent(parser, amount, names.getAmount());
1✔
65
        checkPresent(parser, currency, names.getCurrency());
1✔
66

67
        return factory.create(amount, currency);
1✔
68
    }
69

70
    private void checkPresent(final JsonParser parser, @Nullable final Object value, final String name)
71
            throws JsonParseException {
72
        if (value == null) {
1✔
73
            throw new JsonParseException(parser, format("Missing property: '%s'", name));
1✔
74
        }
75
    }
1✔
76

77
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc