3
3
4
4
package com .azure .core .serializer .json .jackson .implementation ;
5
5
6
- import com .azure .core .implementation .util .BinaryDataContent ;
7
- import com .azure .core .implementation .util .BinaryDataHelper ;
8
- import com .azure .core .implementation .util .ByteArrayContent ;
9
- import com .azure .core .implementation .util .FileContent ;
10
- import com .azure .core .implementation .util .FluxByteBufferContent ;
11
- import com .azure .core .implementation .util .InputStreamContent ;
12
- import com .azure .core .implementation .util .SerializableContent ;
13
- import com .azure .core .implementation .util .StringContent ;
14
6
import com .azure .core .util .BinaryData ;
15
- import com .azure .core .util .logging .ClientLogger ;
16
7
import com .fasterxml .jackson .core .JsonGenerator ;
17
8
import com .fasterxml .jackson .databind .JsonSerializer ;
18
9
import com .fasterxml .jackson .databind .SerializerProvider ;
24
15
* Custom serializer for serializing {@link BinaryData}.
25
16
*/
26
17
final class BinaryDataSerializer extends JsonSerializer <BinaryData > {
27
- private static final ClientLogger LOGGER = new ClientLogger (BinaryDataSerializer .class );
28
-
29
18
/**
30
19
* Gets a module wrapping this serializer as an adapter for the Jackson ObjectMapper.
31
20
*
@@ -43,19 +32,6 @@ public void serialize(BinaryData value, JsonGenerator gen, SerializerProvider se
43
32
return ;
44
33
}
45
34
46
- BinaryDataContent content = BinaryDataHelper .getContent (value );
47
- if (content instanceof ByteArrayContent
48
- || content instanceof FileContent
49
- || content instanceof FluxByteBufferContent
50
- || content instanceof InputStreamContent ) {
51
- gen .writeBinary (content .toBytes ());
52
- } else if (content instanceof SerializableContent ) {
53
- gen .writeRawValue (content .toString ());
54
- } else if (content instanceof StringContent ) {
55
- gen .writeString (content .toString ());
56
- } else {
57
- throw LOGGER .logExceptionAsError (
58
- new IllegalStateException ("Unsupported BinaryData content type: " + content .getClass ().getName ()));
59
- }
35
+ value .writeTo (new JacksonJsonWriter (gen ));
60
36
}
61
37
}
0 commit comments