File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed
johnzon-jsonb/src/test/java/org/apache/johnzon/jsonb
johnzon-mapper/src/main/java/org/apache/johnzon/mapper Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -234,6 +234,23 @@ public void adaptCollectionValue() {
234234 assertEquals ("42" , adaptedBazCollection .collection .get (0 ).value );
235235 }
236236
237+ @ Test
238+ public void testArrayOfClassWithTypeAdapter () {
239+ final Jsonb jsonb = JsonbBuilder .create (
240+ new JsonbConfig ()
241+ .setProperty ("johnzon.readAttributeBeforeWrite" , true )
242+ .withPropertyOrderStrategy (PropertyOrderStrategy .LEXICOGRAPHICAL ) /* assertEquals() order */ );
243+
244+ Baz [] bazs = new Baz []{new Baz ("A" ), new Baz ("B" )};
245+ final String bazsJson = jsonb .toJson (bazs );
246+ assertEquals ("[\" A\" ,\" B\" ]" , bazsJson );
247+
248+
249+ // and the other way around:
250+ final Baz [] bazs2 = jsonb .fromJson (bazsJson , Baz [].class );
251+ assertEquals (2 , bazs2 .length );
252+ }
253+
237254 public static class BarCollection {
238255 @ JsonbTypeAdapter (BarAdapter .class )
239256 public List <Bar > collection ;
@@ -336,6 +353,13 @@ public TypeInstance adaptToJson(final Bar obj) throws Exception {
336353
337354 @ JsonbTypeAdapter (BazAdapter .class )
338355 public static class Baz {
356+ public Baz () {
357+ }
358+
359+ public Baz (String value ) {
360+ this .value = value ;
361+ }
362+
339363 public String value ;
340364 }
341365
Original file line number Diff line number Diff line change @@ -1219,6 +1219,12 @@ private Adapter findAdapter(final Type aClass) {
12191219 }
12201220 return adapter ;
12211221 }
1222+
1223+ final Mappings .ClassMapping classMapping = mappings .getClassMapping (aClass );
1224+ if (classMapping != null && classMapping .adapter != null ) {
1225+ return classMapping .adapter ;
1226+ }
1227+
12221228 config .getNoParserAdapterTypes ().add (aClass );
12231229 return null ;
12241230 }
You can’t perform that action at this time.
0 commit comments