-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #79 from sankala-dremio/master
Added support for Unwrapped Serialization.
- Loading branch information
Showing
2 changed files
with
76 additions
and
3 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
53 changes: 53 additions & 0 deletions
53
src/test/java/com/hubspot/jackson/datatype/protobuf/builtin/UnwrappedSerializationTest.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,53 @@ | ||
package com.hubspot.jackson.datatype.protobuf.builtin; | ||
|
||
import static com.hubspot.jackson.datatype.protobuf.util.ObjectMapperHelper.camelCase; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.io.IOException; | ||
|
||
import org.junit.Test; | ||
|
||
import com.fasterxml.jackson.annotation.JsonUnwrapped; | ||
import com.google.protobuf.ListValue; | ||
import com.google.protobuf.NullValue; | ||
import com.google.protobuf.Value; | ||
import com.hubspot.jackson.datatype.protobuf.util.BuiltInProtobufs; | ||
|
||
public class UnwrappedSerializationTest { | ||
@Test | ||
public void itWritesUnwrappedNullValue() throws IOException { | ||
BuiltInProtobufs.HasValue message = BuiltInProtobufs.HasValue | ||
.newBuilder() | ||
.setValue(Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build()) | ||
.build(); | ||
ValueBean bean = new ValueBean(); | ||
bean.setHasValue(message); | ||
String json = camelCase().writeValueAsString(bean); | ||
assertThat(json).isEqualTo("{\"value\":null}"); | ||
} | ||
|
||
@Test | ||
public void itWritesUnwrappedListValue() throws IOException { | ||
ListValue list = ListValue.newBuilder().addValues(Value.newBuilder().setStringValue("test").build()).build(); | ||
BuiltInProtobufs.HasValue message = BuiltInProtobufs.HasValue | ||
.newBuilder() | ||
.setValue(Value.newBuilder().setListValue(list).build()) | ||
.build(); | ||
ValueBean bean = new ValueBean(); | ||
bean.setHasValue(message); | ||
String json = camelCase().writeValueAsString(bean); | ||
assertThat(json).isEqualTo("{\"value\":[\"test\"]}"); | ||
} | ||
|
||
public static class ValueBean { | ||
@JsonUnwrapped | ||
private BuiltInProtobufs.HasValue hasValue; | ||
|
||
public BuiltInProtobufs.HasValue getHasValue() { | ||
return hasValue; | ||
} | ||
public void setHasValue(BuiltInProtobufs.HasValue hasValue) { | ||
this.hasValue = hasValue; | ||
} | ||
} | ||
} |