|
15 | 15 | */ |
16 | 16 | package com.palantir.javaformat; |
17 | 17 |
|
18 | | -import com.fasterxml.jackson.core.JsonGenerator; |
19 | | -import com.fasterxml.jackson.databind.JsonSerializer; |
20 | | -import com.fasterxml.jackson.databind.SerializerProvider; |
21 | | -import com.fasterxml.jackson.databind.annotation.JsonSerialize; |
22 | 18 | import com.google.errorprone.annotations.Immutable; |
23 | 19 | import com.palantir.javaformat.doc.Doc; |
24 | 20 | import com.palantir.javaformat.doc.Level; |
25 | | -import java.io.IOException; |
26 | | -import java.io.UncheckedIOException; |
27 | 21 | import org.derive4j.ArgOption; |
28 | 22 | import org.derive4j.Data; |
| 23 | +import tools.jackson.core.JsonGenerator; |
| 24 | +import tools.jackson.databind.SerializationContext; |
| 25 | +import tools.jackson.databind.ValueSerializer; |
| 26 | +import tools.jackson.databind.annotation.JsonSerialize; |
29 | 27 |
|
30 | 28 | @Data(arguments = ArgOption.checkedNotNull) |
31 | 29 | @Immutable |
@@ -72,45 +70,28 @@ public interface Cases<R> { |
72 | 70 | * This is gross but just wanted to get something working. See https://github.com/derive4j/derive4j/issues/51 for a |
73 | 71 | * potential better implementation. |
74 | 72 | */ |
75 | | - static class Json extends JsonSerializer<BreakBehaviour> { |
| 73 | + static class Json extends ValueSerializer<BreakBehaviour> { |
76 | 74 |
|
77 | 75 | @Override |
78 | | - public void serialize(BreakBehaviour value, JsonGenerator gen, SerializerProvider serializers) |
79 | | - throws IOException { |
| 76 | + public void serialize(BreakBehaviour value, JsonGenerator gen, SerializationContext serializers) { |
80 | 77 | gen.writeStartObject(); |
81 | 78 | BreakBehaviours.caseOf(value) |
82 | 79 | .breakThisLevel(() -> { |
83 | | - try { |
84 | | - gen.writeObjectField("type", "breakThisLevel"); |
85 | | - } catch (IOException e) { |
86 | | - throw new UncheckedIOException(e); |
87 | | - } |
| 80 | + gen.writeStringProperty("type", "breakThisLevel"); |
88 | 81 | return null; |
89 | 82 | }) |
90 | 83 | .preferBreakingLastInnerLevel(keepIndentWhenInlined -> { |
91 | | - try { |
92 | | - gen.writeObjectField("type", "preferBreakingLastInnerLevel"); |
93 | | - gen.writeObjectField("keepIndentWhenInlined", keepIndentWhenInlined); |
94 | | - } catch (IOException e) { |
95 | | - throw new UncheckedIOException(e); |
96 | | - } |
| 84 | + gen.writeStringProperty("type", "preferBreakingLastInnerLevel"); |
| 85 | + gen.writeBooleanProperty("keepIndentWhenInlined", keepIndentWhenInlined); |
97 | 86 | return null; |
98 | 87 | }) |
99 | 88 | .inlineSuffix(() -> { |
100 | | - try { |
101 | | - gen.writeObjectField("type", "inlineSuffix"); |
102 | | - } catch (IOException e) { |
103 | | - throw new UncheckedIOException(e); |
104 | | - } |
| 89 | + gen.writeStringProperty("type", "inlineSuffix"); |
105 | 90 | return null; |
106 | 91 | }) |
107 | 92 | .breakOnlyIfInnerLevelsThenFitOnOneLine(keepIndentWhenInlined -> { |
108 | | - try { |
109 | | - gen.writeObjectField("type", "breakOnlyIfInnerLevelsThenFitOnOneLine"); |
110 | | - gen.writeObjectField("keepIndentWhenInlined", keepIndentWhenInlined); |
111 | | - } catch (IOException e) { |
112 | | - throw new UncheckedIOException(e); |
113 | | - } |
| 93 | + gen.writeStringProperty("type", "breakOnlyIfInnerLevelsThenFitOnOneLine"); |
| 94 | + gen.writeBooleanProperty("keepIndentWhenInlined", keepIndentWhenInlined); |
114 | 95 | return null; |
115 | 96 | }); |
116 | 97 | gen.writeEndObject(); |
|
0 commit comments