-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[jsonb] JsonB support use of JsonObject for @Json.Unmapped type (#315)
So Unmapped type can either be a Map<String,Object> or a JsonObject.
- Loading branch information
Showing
4 changed files
with
79 additions
and
13 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
blackbox-test/src/main/java/org/example/customer/node/HelloWithUnmapped.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,12 @@ | ||
package org.example.customer.node; | ||
|
||
import io.avaje.json.node.JsonObject; | ||
import io.avaje.jsonb.Json; | ||
|
||
@Json | ||
public record HelloWithUnmapped( | ||
String name, | ||
int count, | ||
@Json.Unmapped | ||
JsonObject other) { | ||
} |
25 changes: 25 additions & 0 deletions
25
blackbox-test/src/test/java/org/example/customer/node/HelloWithUnmappedTest.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,25 @@ | ||
package org.example.customer.node; | ||
|
||
import io.avaje.json.node.JsonObject; | ||
import io.avaje.jsonb.JsonType; | ||
import io.avaje.jsonb.Jsonb; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class HelloWithUnmappedTest { | ||
|
||
Jsonb jsonb = Jsonb.builder().build(); | ||
JsonType<HelloWithUnmapped> jsonType = jsonb.type(HelloWithUnmapped.class); | ||
|
||
@Test | ||
void test() { | ||
var source = new HelloWithUnmapped("hi", 3, JsonObject.create().add("extra", "b").add("extra2", 54L)); | ||
|
||
String asJson = jsonType.toJson(source); | ||
assertThat(asJson).isEqualTo("{\"name\":\"hi\",\"count\":3,\"extra\":\"b\",\"extra2\":54}"); | ||
|
||
HelloWithUnmapped fromJson = jsonType.fromJson(asJson); | ||
assertThat(fromJson).isEqualTo(source); | ||
} | ||
} |
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