File tree Expand file tree Collapse file tree 6 files changed +73
-3
lines changed
main/java/sh/arnaud/javaserde/codec
test/resources/sh/arnaud/javaserde/units/009-nullable Expand file tree Collapse file tree 6 files changed +73
-3
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ plugins {
33}
44
55group = ' sh.arnaud'
6- version = ' 1.0.1 -SNAPSHOT'
6+ version = ' 1.0.2 -SNAPSHOT'
77
88repositories {
99 mavenCentral()
Original file line number Diff line number Diff line change @@ -116,7 +116,15 @@ private GrammarNewEnum readNewEnum(ByteBuffer data) throws Exception {
116116 }
117117
118118 private GrammarNewArray readNewArray (ByteBuffer data ) throws Exception {
119- if (peekByte (data ) == TC_REFERENCE ) {
119+ var peeked = peekByte (data );
120+
121+ if (peeked == TC_NULL ) {
122+ data .get ();
123+
124+ return null ;
125+ }
126+
127+ if (peeked == TC_REFERENCE ) {
120128 data .get ();
121129
122130 return handles .retrieve (data .getInt (), GrammarNewArray .class );
Original file line number Diff line number Diff line change @@ -64,7 +64,7 @@ private void writeContent(GrammarContent content) throws Exception {
6464 return ;
6565 }
6666
67- throw new UnsupportedOperationException ("Serialization of content not implemented yet!" );
67+ throw new UnsupportedOperationException ("Serialization of content not implemented yet: " . concat ( content . getClass (). getName ()) );
6868 }
6969
7070 private void referenceable (GrammarObject object , Callable <Void > runnable ) throws Exception {
@@ -105,6 +105,11 @@ private void writeNewEnum(GrammarNewEnum newEnum) throws Exception {
105105
106106 private void writeNewArray (GrammarNewArray array ) throws Exception {
107107 referenceable (array , () -> {
108+ if (array == null ) {
109+ buffer .writeByte (TC_NULL );
110+ return null ;
111+ }
112+
108113 buffer .writeByte (TC_ARRAY );
109114 writeClassDesc (array .classDesc );
110115
Original file line number Diff line number Diff line change 1+ import java .io .*;
2+ import java .util .Date ;
3+
4+ public class Nullable implements Serializable {
5+ enum Enum {
6+ ONE ,
7+ TWO
8+ }
9+
10+ private final String null_string = null ;
11+ private final int [] null_ints = null ;
12+ private final Enum null_enum = null ;
13+
14+ public static void main (String args []) throws Exception {
15+ var stream = new ObjectOutputStream (System .out );
16+
17+ stream .writeObject (new Nullable ());
18+ stream .flush ();
19+ }
20+ }
Original file line number Diff line number Diff line change 1+ [
2+ {
3+ "@handle" : 8257540 ,
4+ "@class" : {
5+ "@handle" : 8257536 ,
6+ "@name" : " Nullable" ,
7+ "@serial" : 9613321951376902 ,
8+ "@flags" : 2 ,
9+ "@fields" : [
10+ {
11+ "@name" : " null_enum" ,
12+ "@type" : " LNullable$Enum;"
13+ },
14+ {
15+ "@name" : " null_ints" ,
16+ "@type" : " [I"
17+ },
18+ {
19+ "@name" : " null_string" ,
20+ "@type" : " Ljava/lang/String;"
21+ }
22+ ],
23+ "@annotations" : [],
24+ "@super" : null
25+ },
26+ "@data" : [
27+ {
28+ "@values" : [
29+ null ,
30+ null ,
31+ null
32+ ],
33+ "@annotations" : []
34+ }
35+ ]
36+ }
37+ ]
You can’t perform that action at this time.
0 commit comments