Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.example.customer.stream;

import io.avaje.jsonb.Json;

import java.util.ArrayList;

@Json
public record MyArrayList(int id, ArrayList<String> names) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.example.customer.stream;

import io.avaje.jsonb.Json;

import java.util.LinkedHashSet;

@Json
public record MyLinked(int id, LinkedHashSet<String> names) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.example.customer.stream;

import io.avaje.jsonb.Jsonb;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

class MyArrayListTest {

Jsonb jsonb = Jsonb.builder().build();

@Test
void toJson_fromJson() {
MyArrayList myLinked = new MyArrayList(1, new ArrayList<>(List.of("a", "b", "c")));

String json = jsonb.toJson(myLinked);
assertNotNull(json);
assertThat(json).isEqualTo("{\"id\":1,\"names\":[\"a\",\"b\",\"c\"]}");

MyArrayList fromJson = jsonb.type(MyArrayList.class).fromJson(json);
assertEquals(myLinked, fromJson);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.example.customer.stream;

import io.avaje.jsonb.Jsonb;
import org.junit.jupiter.api.Test;

import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.*;

class MyLinkedHashSetTest {

Jsonb jsonb = Jsonb.builder().build();

@Test
void toJson_fromJson() {
MyLinked myLinked = new MyLinked(1, new LinkedHashSet<>(List.of("a", "b", "c")));

String json = jsonb.toJson(myLinked);
assertNotNull(json);
assertThat(json).isEqualTo("{\"id\":1,\"names\":[\"a\",\"b\",\"c\"]}");

MyLinked fromJson = jsonb.type(MyLinked.class).fromJson(json);
assertEquals(myLinked, fromJson);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -167,22 +167,22 @@ private String asTypeBasic() {
if (adapterType != null) {
return adapterType;
}
return Util.shortName(topType)+".class";
return Util.shortName(topType) + ".class";
}

private String asTypeContainer() {
GenericType param = params.get(0);
String containerType = topType();
if (isAssignable(containerType, "java.util.List")) {
if ("java.util.List".equals(containerType) || "java.util.ArrayList".equals(containerType)) {
return "Types.listOf(" + Util.shortName(param.topType()) + ".class)";
}
if (isAssignable(containerType, "java.util.Set")) {
if ("java.util.Set".equals(containerType) || "java.util.LinkedHashSet".equals(containerType)) {
return "Types.setOf(" + Util.shortName(param.topType()) + ".class)";
}
if (isAssignable(containerType, "java.util.stream.Stream")) {
if ("java.util.stream.Stream".equals(containerType)) {
return "Types.streamOf(" + Util.shortName(param.topType()) + ".class)";
}
if (isAssignable(containerType, "java.util.Optional")) {
if ("java.util.Optional".equals(containerType)) {
return "Types.optionalOf(" + Util.shortName(param.topType()) + ".class)";
}
return null;
Expand Down