2
2
3
3
import com .fasterxml .jackson .core .JsonProcessingException ;
4
4
import com .fasterxml .jackson .databind .JsonNode ;
5
- import com .fasterxml .jackson .databind .ObjectMapper ;
6
5
import com .fasterxml .jackson .databind .node .BooleanNode ;
7
6
import com .fasterxml .jackson .databind .node .TextNode ;
8
- import com .fasterxml . jackson . dataformat . yaml . YAMLFactory ;
7
+ import com .github . andreaTP . opa . chicory . Opa ;
9
8
import com .github .andreaTP .opa .chicory .OpaBuiltin ;
10
9
11
10
public class Yaml {
12
- public static ObjectMapper yamlMapper = new ObjectMapper (new YAMLFactory ());
13
-
14
- // maybe: .disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER));
15
11
16
12
private static JsonNode isValidImpl (JsonNode boxedYaml ) {
17
13
if (!boxedYaml .isTextual ()) {
18
14
return BooleanNode .getFalse ();
19
15
} else {
20
16
try {
21
- yamlMapper .readTree (boxedYaml .asText ());
17
+ Opa . yamlMapper .readTree (boxedYaml .asText ());
22
18
return BooleanNode .getTrue ();
23
19
} catch (JsonProcessingException e ) {
24
20
return BooleanNode .getFalse ();
@@ -34,7 +30,7 @@ private static JsonNode unmarshalImpl(JsonNode boxedYaml) {
34
30
throw new RuntimeException ("yaml is not correctly boxed in a Json string" );
35
31
} else {
36
32
try {
37
- return yamlMapper .readTree (boxedYaml .asText ());
33
+ return Opa . yamlMapper .readTree (boxedYaml .asText ());
38
34
} catch (JsonProcessingException e ) {
39
35
// should ignore errors here ...
40
36
return BooleanNode .getFalse ();
@@ -47,7 +43,7 @@ private static JsonNode unmarshalImpl(JsonNode boxedYaml) {
47
43
48
44
public static JsonNode marshalImpl (JsonNode json ) {
49
45
try {
50
- return TextNode .valueOf (yamlMapper .writeValueAsString (json ));
46
+ return TextNode .valueOf (Opa . yamlMapper .writeValueAsString (json ));
51
47
} catch (JsonProcessingException e ) {
52
48
throw new RuntimeException (e );
53
49
}
0 commit comments