Skip to content
This repository was archived by the owner on Sep 21, 2020. It is now read-only.

Commit ef94e6f

Browse files
authored
Merge pull request #19 from aontas/master
Ensure round-trip serialization is consistent
2 parents 380b0bc + a6287bb commit ef94e6f

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

src/main/java/com/opower/unitsofmeasure/UnitJsonDeserializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public UnitJsonDeserializer() {
2525
public Unit deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
2626
JsonToken currentToken = jsonParser.getCurrentToken();
2727
if (currentToken == JsonToken.VALUE_STRING) {
28-
return UCUMFormat.getInstance(UCUMFormat.Variant.CASE_INSENSITIVE).parse(jsonParser.getText(), new ParsePosition(0));
28+
return UCUMFormat.getInstance(UCUMFormat.Variant.CASE_SENSITIVE).parse(jsonParser.getText(), new ParsePosition(0));
2929
}
3030
throw deserializationContext.wrongTokenException(jsonParser, JsonToken.VALUE_STRING, "Expected unit value in String format");
3131
}

src/test/java/com/opower/unitsofmeasure/UnitJacksonModuleTest.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414

1515
import static org.junit.Assert.*;
1616
import org.junit.Before;
17-
import org.junit.Ignore;
1817
import org.junit.Test;
1918

2019
import systems.uom.ucum.UCUM;
2120
import static tec.uom.se.AbstractUnit.ONE;
2221
import static tec.uom.se.unit.MetricPrefix.KILO;
22+
import static tec.uom.se.unit.MetricPrefix.MEGA;
2323
import static tec.uom.se.unit.MetricPrefix.MILLI;
2424
import tec.uom.se.unit.Units;
2525

@@ -104,12 +104,18 @@ public void testParseWithUnrecognizedField() throws Exception {
104104
}
105105

106106
@Test
107-
@Ignore("solve km formatting") // TODO solve km parsing
108107
public void testParseLengthKm() throws Exception {
109108
Unit<?> parsedUnit = parse("\"km\"", Unit.class);
110109
assertEquals("The Unit<Length> in the parsed JSON doesn't match", KILO(Units.METRE), parsedUnit);
111110
}
112111

112+
@Test
113+
public void testRoundTripSerialization() throws Exception {
114+
String serialized = serialize(MEGA(UCUM.METER));
115+
Unit<?> parsedUnit = parse(serialized, Unit.class);
116+
assertEquals("The Unit<Length> in the parsed JSON doesn't match", MEGA(UCUM.METER), parsedUnit);
117+
}
118+
113119
protected String serialize(Object objectToSerialize) throws IOException {
114120
final Writer writer = new StringWriter();
115121
final JsonGenerator generator = this.jsonFactory.createJsonGenerator(writer);

0 commit comments

Comments
 (0)