File tree 2 files changed +30
-0
lines changed
main/java/io/kubernetes/client
test/java/io/kubernetes/client
2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -126,11 +126,14 @@ public class ByteArrayAdapter extends TypeAdapter<byte[]> {
126
126
127
127
@ Override
128
128
public void write (JsonWriter out , byte [] value ) throws IOException {
129
+ boolean oldHtmlSafe = out .isHtmlSafe ();
130
+ out .setHtmlSafe (false );
129
131
if (value == null ) {
130
132
out .nullValue ();
131
133
} else {
132
134
out .value (ByteString .of (value ).base64 ());
133
135
}
136
+ out .setHtmlSafe (oldHtmlSafe );
134
137
}
135
138
136
139
@ Override
Original file line number Diff line number Diff line change
1
+ package io .kubernetes .client ;
2
+
3
+ import okio .ByteString ;
4
+ import org .junit .Test ;
5
+
6
+ import static org .hamcrest .CoreMatchers .is ;
7
+ import static org .junit .Assert .*;
8
+
9
+ public class JSONTest {
10
+
11
+ @ Test
12
+ public void testSerializeByteArray () {
13
+ final JSON json = new JSON ();
14
+ final String plainText = "string that contains '=' when encoded" ;
15
+ final String base64String = json .serialize (plainText .getBytes ());
16
+ //serialize returns string surrounded by quotes: "\"[base64]\""
17
+ final String pureString = base64String .replaceAll ("^\" |\" $" , "" );
18
+ final ByteString byteStr = ByteString .decodeBase64 (pureString );
19
+
20
+ //Check encoded to valid base64
21
+ assertNotNull (byteStr );
22
+
23
+ //Check encoded string correctly
24
+ final String decodedText =new String (byteStr .toByteArray ());
25
+ assertThat (decodedText , is (plainText ));
26
+ }
27
+ }
You can’t perform that action at this time.
0 commit comments