XML -> JAXB, JSON.write(...) 추가

master
mjkhan21 12 months ago
parent 89c9994f0f
commit e36b0b3642

@ -19,14 +19,14 @@ import cokr.xit.foundation.AbstractComponent;
/**XML /
* @author mjkhan
*/
public class XML extends AbstractComponent {
public class JAXB extends AbstractComponent {
private String charset;
private HashMap<Class<?>, Support> xctxes;
/** XML() .
* @param charset . .
*/
public XML(String charset) {
public JAXB(String charset) {
this.charset = ifEmpty(charset, () -> Charset.defaultCharset().name());
}

@ -1,6 +1,7 @@
package cokr.xit.foundation.data;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.UnaryOperator;
@ -145,6 +146,39 @@ public class JSON extends AbstractComponent {
}
}
/** OutputStream .
* @param out OutputStream
* @param obj
* @param indent
* <ul><li> true</li>
* <li> false</li>
* </ul>
*/
public void write(OutputStream out, Object obj, boolean indent) {
ObjectMapper mapper = getObjectMapper();
ObjectWriter writer = null;
if (!indent) {
writer = filterProvider == null ? mapper.writer() : mapper.writer(filterProvider);
} else {
writer = mapper.writerWithDefaultPrettyPrinter();
if (filterProvider != null)
writer = writer.with(filterProvider);
}
try {
writer.writeValue(out, obj);
} catch (Exception e) {
throw runtimeException(e);
}
}
/** OutputStream .
* @param out OutputStream
* @param obj
*/
public void write(OutputStream out, Object obj) {
write(out, obj, false);
}
/** JSON .<br />
* {@code @JsonFilter("필터 아이디")} .
* @author mjkhan

Loading…
Cancel
Save