-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH-43 Adds support for NumberValue serializer
- Loading branch information
1 parent
943a060
commit 76d2af4
Showing
5 changed files
with
80 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/main/java/org/zalando/jackson/datatype/money/NumberValueSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.zalando.jackson.datatype.money; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.databind.JsonSerializer; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
import java.io.IOException; | ||
import java.math.BigDecimal; | ||
import javax.money.NumberValue; | ||
|
||
public class NumberValueSerializer extends JsonSerializer<NumberValue> { | ||
|
||
@Override | ||
public void serialize(final NumberValue value, final JsonGenerator generator, final SerializerProvider serializers) throws IOException { | ||
final BigDecimal amount = value.numberValueExact(BigDecimal.class); | ||
generator.writeNumber(amount); | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/org/zalando/jackson/datatype/money/StringNumberValueSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.zalando.jackson.datatype.money; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.databind.JsonSerializer; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
import java.io.IOException; | ||
import java.math.BigDecimal; | ||
import javax.money.NumberValue; | ||
|
||
public class StringNumberValueSerializer extends JsonSerializer<NumberValue> { | ||
|
||
@Override | ||
public void serialize(final NumberValue value, final JsonGenerator generator, final SerializerProvider serializers) throws IOException { | ||
final BigDecimal amount = value.numberValueExact(BigDecimal.class); | ||
generator.writeString(amount.toString()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters