Skip to content

Commit 6032cf5

Browse files
committed
Merge remote-tracking branch 'upstream/main' into type
2 parents b46f30c + effb6d2 commit 6032cf5

File tree

30 files changed

+236
-163
lines changed

30 files changed

+236
-163
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ build/
77
*.classpath
88
*.project
99
*.class
10+
.DS_Store

blackbox-test/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>io.avaje</groupId>
66
<artifactId>avaje-jsonb-parent</artifactId>
7-
<version>1.4-RC8</version>
7+
<version>1.4-RC9</version>
88
</parent>
99

1010
<artifactId>blackbox-test</artifactId>
@@ -28,7 +28,7 @@
2828
<dependency>
2929
<groupId>io.avaje</groupId>
3030
<artifactId>avaje-jsonb</artifactId>
31-
<version>1.4-RC8</version>
31+
<version>1.4-RC9</version>
3232
</dependency>
3333

3434
<!-- <dependency>-->
@@ -40,7 +40,7 @@
4040
<dependency>
4141
<groupId>io.avaje</groupId>
4242
<artifactId>avaje-jsonb-generator</artifactId>
43-
<version>1.4-RC8</version>
43+
<version>1.4-RC9</version>
4444
<scope>provided</scope>
4545
</dependency>
4646

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package org.example.customer;
2+
3+
import io.avaje.jsonb.Json;
4+
5+
import java.util.Map;
6+
7+
@Json
8+
public class ALBResponse {
9+
10+
private final int statusCode;
11+
private final boolean isBase64Encoded;
12+
private final Map<String, String> headers;
13+
private final String body;
14+
15+
public ALBResponse(int statusCode, boolean isBase64Encoded, Map<String, String> headers, String body) {
16+
this.statusCode = statusCode;
17+
this.isBase64Encoded = isBase64Encoded;
18+
this.headers = headers;
19+
this.body = body;
20+
}
21+
22+
public int getStatusCode() {
23+
return statusCode;
24+
}
25+
26+
public boolean isBase64Encoded() {
27+
return isBase64Encoded;
28+
}
29+
30+
public Map<String, String> getHeaders() {
31+
return headers;
32+
}
33+
34+
public String getBody() {
35+
return body;
36+
}
37+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package org.example.customer;
2+
3+
import io.avaje.jsonb.Json;
4+
5+
import java.util.Map;
6+
7+
@Json
8+
public record ALBResponse2 (int one, Map<String, String> map1, int two, Map<String, String> map2, String three) {
9+
10+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package org.example.customer;
2+
3+
import io.avaje.jsonb.JsonType;
4+
import io.avaje.jsonb.Jsonb;
5+
import org.junit.jupiter.api.Test;
6+
7+
import java.util.Map;
8+
9+
import static org.assertj.core.api.Assertions.assertThat;
10+
11+
class ALBResponseTest {
12+
13+
private final Jsonb jsonb = Jsonb.builder().build();
14+
15+
@Test
16+
void toJson() {
17+
ALBResponse response = new ALBResponse(200, false, Map.of("foo", "bar"), "content");
18+
19+
JsonType<ALBResponse> type = jsonb.type(ALBResponse.class);
20+
String asJson = type.toJson(response);
21+
22+
ALBResponse response1 = type.fromJson(asJson);
23+
assertThat(response1.getStatusCode()).isEqualTo(response1.getStatusCode());
24+
assertThat(response1.getBody()).isEqualTo("content");
25+
assertThat(response1.isBase64Encoded()).isFalse();
26+
assertThat(response1.getHeaders()).hasSize(1);
27+
assertThat(response1.getHeaders()).containsEntry("foo", "bar");
28+
}
29+
30+
@Test
31+
void toJsonTwoScalarMaps() {
32+
ALBResponse2 response = new ALBResponse2(10, Map.of("foo", "bar"), 20, Map.of("baz", "waz"), "content");
33+
34+
JsonType<ALBResponse2> type = jsonb.type(ALBResponse2.class);
35+
String asJson = type.toJson(response);
36+
37+
ALBResponse2 response1 = type.fromJson(asJson);
38+
assertThat(response1).isEqualTo(response);
39+
}
40+
}

jsonb-generator/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>io.avaje</groupId>
66
<artifactId>avaje-jsonb-parent</artifactId>
7-
<version>1.4-RC8</version>
7+
<version>1.4-RC9</version>
88
</parent>
99

1010
<artifactId>avaje-jsonb-generator</artifactId>

jsonb-generator/src/main/java/io/avaje/jsonb/generator/ClassReader.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,7 @@ public void writeToJson(Append writer) {
264264
writer.eol();
265265
writer.append(" @Override").eol();
266266
writer.append(" public void toJson(JsonWriter writer, %s %s) {", shortName, varName).eol();
267-
writer.append(" writer.beginObject();").eol();
268-
writer.append(" writer.names(names);").eol();
267+
writer.append(" writer.beginObject(names);").eol();
269268
if (hasSubTypes) {
270269
writeToJsonForSubtypes(writer, varName);
271270
} else {
@@ -418,8 +417,7 @@ String constructorParamName(String name) {
418417
private void writeFromJsonSwitch(Append writer, boolean defaultConstructor, String varName) {
419418
writer.eol();
420419
writer.append(" // read json").eol();
421-
writer.append(" reader.beginObject();").eol();
422-
writer.append(" reader.names(names);").eol();
420+
writer.append(" reader.beginObject(names);").eol();
423421
writer.append(" while (reader.hasNextField()) {").eol();
424422
if (caseInsensitiveKeys) {
425423
writer.append(" final String origFieldName = reader.nextField();").eol();

jsonb-jackson/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<artifactId>avaje-jsonb-parent</artifactId>
66
<groupId>io.avaje</groupId>
7-
<version>1.4-RC8</version>
7+
<version>1.4-RC9</version>
88
</parent>
99

1010
<artifactId>avaje-jsonb-jackson</artifactId>
@@ -21,7 +21,7 @@
2121
<dependency>
2222
<groupId>io.avaje</groupId>
2323
<artifactId>avaje-jsonb</artifactId>
24-
<version>1.4-RC8</version>
24+
<version>1.4-RC9</version>
2525
</dependency>
2626

2727
<dependency>

jsonb-jackson/src/main/java/io/avaje/jsonb/jackson/ArrayStack.java

Lines changed: 0 additions & 41 deletions
This file was deleted.

jsonb-jackson/src/main/java/io/avaje/jsonb/jackson/JacksonNames.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
final class JacksonNames implements PropertyNames {
77

8+
static final JacksonNames EMPTY = new JacksonNames(new String[0]);
9+
810
private static final NameCache NAME_CACHE = new NameCache();
911

1012
private final SerializedString[] keys;

0 commit comments

Comments
 (0)