use of com.fasterxml.jackson.core.JsonGenerationException in project uPortal by Jasig.
the class JacksonColumnMapper method toNonNullValue.
@Override
public final String toNonNullValue(Object value) {
try {
final Class<? extends Object> type = value.getClass();
final ObjectWriter typeWriter = typedObjectWriters.getUnchecked(type);
final String valueAsString = typeWriter.writeValueAsString(value);
return objectWriter.writeValueAsString(new JsonWrapper(type, valueAsString));
} catch (JsonGenerationException e) {
throw new IllegalArgumentException("Could not write to JSON: " + value, e);
} catch (JsonMappingException e) {
throw new IllegalArgumentException("Could not write to JSON: " + value, e);
} catch (IOException e) {
throw new IllegalArgumentException("Could not write to JSON: " + value, e);
}
}
use of com.fasterxml.jackson.core.JsonGenerationException in project camel by apache.
the class MultiSelectPicklistSerializer method serialize.
@Override
public void serialize(Object value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
// get Picklist enum element class from array class
Class<?> arrayClass = value.getClass();
final Class<?> aClass = arrayClass.getComponentType();
try {
Method getterMethod = aClass.getMethod("value");
final int length = Array.getLength(value);
// construct a string of form value1;value2;...
final StringBuilder buffer = new StringBuilder();
for (int i = 0; i < length; i++) {
buffer.append((String) getterMethod.invoke(Array.get(value, i)));
if (i < (length - 1)) {
buffer.append(';');
}
}
jgen.writeString(buffer.toString());
} catch (Exception e) {
throw new JsonGenerationException(String.format("Exception writing pick list value %s of type %s: %s", value, value.getClass().getName(), e.getMessage()), jgen);
}
}
use of com.fasterxml.jackson.core.JsonGenerationException in project camel by apache.
the class StringMultiSelectPicklistSerializer method serialize.
@Override
public void serialize(Object value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
try {
String[] a = (String[]) value;
final int length = a.length;
// construct a string of form value1;value2;...
final StringBuilder buffer = new StringBuilder();
for (int i = 0; i < length; i++) {
buffer.append(a[i].trim());
if (i < (length - 1)) {
buffer.append(';');
}
}
jgen.writeString(buffer.toString());
} catch (Exception e) {
throw new JsonGenerationException(String.format("Exception writing pick list value %s of type %s: %s", value, value.getClass().getName(), e.getMessage()), jgen);
}
}
use of com.fasterxml.jackson.core.JsonGenerationException in project cloudstack by apache.
the class CSJacksonAnnotationTest method test.
@Test
@Ignore
public void test() {
ObjectMapper mapper = new ObjectMapper();
JaxbAnnotationModule jaxbModule = new JaxbAnnotationModule();
jaxbModule.setPriority(Priority.SECONDARY);
mapper.registerModule(jaxbModule);
mapper.registerModule(new CSJacksonAnnotationModule());
StringWriter writer = new StringWriter();
TestVO vo = new TestVO(1000, "name");
vo.names = new ArrayList<String>();
vo.names.add("name1");
vo.names.add("name2");
vo.values = new HashMap<String, Long>();
vo.values.put("key1", 1000l);
vo.values.put("key2", 2000l);
vo.vo2.name = "testvoname2";
vo.pods = "abcde";
try {
mapper.writeValue(writer, vo);
} catch (JsonGenerationException e) {
e.printStackTrace();
} catch (JsonMappingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
System.out.print(writer.getBuffer().toString());
}
use of com.fasterxml.jackson.core.JsonGenerationException in project JMRI by JMRI.
the class PanelServlet method getJsonPanel.
@Override
protected String getJsonPanel(String name) {
log.debug("Getting {} for {}", getPanelType(), name);
try {
PanelEditor editor = (PanelEditor) getEditor(name);
ObjectNode root = this.mapper.createObjectNode();
ObjectNode panel = root.putObject("panel");
JFrame frame = editor.getTargetFrame();
panel.put("name", name);
panel.put("height", frame.getContentPane().getHeight());
panel.put("width", frame.getContentPane().getWidth());
panel.put("panelheight", frame.getContentPane().getHeight());
panel.put("panelwidth", frame.getContentPane().getWidth());
panel.put("showtooltips", editor.showTooltip());
panel.put("controlling", editor.allControlling());
if (editor.getBackgroundColor() != null) {
ObjectNode color = panel.putObject("backgroundColor");
color.put("red", editor.getBackgroundColor().getRed());
color.put("green", editor.getBackgroundColor().getGreen());
color.put("blue", editor.getBackgroundColor().getBlue());
}
// include contents
log.debug("N elements: {}", editor.getContents().size());
for (Positionable sub : editor.getContents()) {
try {
// TODO: get all panel contents as JSON
// I tried using JavaBean Introspection to simply build the contents using Jackson Databindings,
// but when a panel element has a reference to the panel or to itself as a property, this leads
// to infinite recursion
} catch (Exception ex) {
log.error("Error storing panel element: " + ex, ex);
}
}
return this.mapper.writeValueAsString(root);
} catch (NullPointerException ex) {
log.warn("Requested Panel [" + name + "] does not exist.");
return "ERROR Requested panel [" + name + "] does not exist.";
} catch (JsonGenerationException e) {
log.error("Error generating JSON", e);
return "ERROR " + e.getLocalizedMessage();
} catch (JsonMappingException e) {
log.error("Error mapping JSON", e);
return "ERROR " + e.getLocalizedMessage();
} catch (IOException e) {
log.error("IOException", e);
return "ERROR " + e.getLocalizedMessage();
}
}
Aggregations