]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms.lib.json/src/org/argeo/cms/acr/json/AcrJsonUtils.java
1 package org
.argeo
.cms
.acr
.json
;
3 import javax
.xml
.namespace
.QName
;
5 import org
.argeo
.api
.acr
.Content
;
6 import org
.argeo
.api
.acr
.NamespaceUtils
;
7 import org
.argeo
.api
.acr
.QNamed
;
9 import jakarta
.json
.stream
.JsonGenerator
;
11 /** Utilities around ACR and the JSON format. */
12 public class AcrJsonUtils
{
13 public static void writeAttr(JsonGenerator g
, Content content
, String attr
) {
14 writeAttr(g
, content
, NamespaceUtils
.parsePrefixedName(attr
));
17 public static void writeAttr(JsonGenerator g
, Content content
, QNamed attr
) {
18 writeAttr(g
, content
, attr
.qName());
21 public static void writeAttr(JsonGenerator g
, Content content
, QName attr
) {
22 // String value = content.attr(attr);
23 Object value
= content
.get(attr
);
25 // TODO specify NamespaceContext
26 String key
= NamespaceUtils
.toPrefixedName(attr
);
27 if (value
instanceof Double v
)
29 else if (value
instanceof Long v
)
31 else if (value
instanceof Integer v
)
33 else if (value
instanceof Boolean v
)
36 g
.write(key
, value
.toString());
41 private AcrJsonUtils() {