use of com.fasterxml.jackson.core.JsonFactory in project wiquery by WiQuery.
the class AutocompleteComponent method onBeforeRenderAutocomplete.
@Override
protected void onBeforeRenderAutocomplete(Autocomplete<?> autocomplete) {
StringWriter sw = new StringWriter();
try {
JsonGenerator gen = new JsonFactory().createGenerator(sw);
List<Object> json = new ArrayList<Object>();
T defaultValue = AutocompleteComponent.this.getModelObject();
AutocompleteJson value = null;
Integer index = 0;
for (T obj : AutocompleteComponent.this.list.getObject()) {
index++;
value = newAutocompleteJson(index, obj);
json.add(value);
if (obj.equals(defaultValue)) {
autocomplete.setDefaultModelObject(value.getLabel());
getAutocompleteHidden().setModelObject(value.getValueId());
}
}
new ObjectMapper().writeValue(gen, json);
} catch (IOException e) {
throw new WicketRuntimeException(e);
}
autocomplete.getOptions().put("source", sw.toString());
}
use of com.fasterxml.jackson.core.JsonFactory in project fastjson by alibaba.
the class JacksonPageModelParser method parse.
/**
* @param content
* @throws JsonParseException
* @throws IOException
*/
public PageInstance parse(String content) throws JsonParseException, IOException {
JsonFactory f = new JsonFactory();
JsonParser parser = f.createJsonParser(content);
// move to the start of the
JsonToken current = parser.nextToken();
// object
// get instanceId
String instanceId = getNextTextValue("sid", parser);
// get pageId
String pageId = getNextTextValue("cid", parser);
// move to field: segments
current = parser.nextToken();
assertExpectedFiled(parser.getCurrentName(), "segments", parser.getCurrentLocation());
PageInstance pageInstance = new PageInstance();
pageInstance.setCid(pageId);
pageInstance.setSid(Long.valueOf(instanceId));
pageInstance.setSegments(parseSegments(parser));
return pageInstance;
// 构建组件树,用于递归渲染
// pageInstance.buildComponentTree();
}
use of com.fasterxml.jackson.core.JsonFactory in project jmxtrans by jmxtrans.
the class SensuWriter2Test method metricsAreFormattedCorrectly.
@Test
public void metricsAreFormattedCorrectly() throws IOException {
StringWriter writer = new StringWriter();
SensuWriter2 sensuWriter = new SensuWriter2(new GraphiteWriter2(ImmutableList.<String>of(), null), new JsonFactory());
sensuWriter.write(writer, ServerFixtures.dummyServer(), QueryFixtures.dummyQuery(), ResultFixtures.dummyResults());
assertThat(writer.toString()).isEqualTo("{\n" + " \"name\" : \"jmxtrans\",\n" + " \"type\" : \"metric\",\n" + " \"handler\" : \"graphite\",\n" + " \"output\" : \"host_example_net_4321.MemoryAlias.ObjectPendingFinalizationCount 10 0\\n\"\n" + "}");
}
use of com.fasterxml.jackson.core.JsonFactory in project rest.li by linkedin.
the class TestJacksonCodec method testNoStringIntern.
/**
* Test to make sure that field names are not interned.
*
* @throws IOException
*/
@Test
public void testNoStringIntern() throws IOException {
final String keyName = "testKey";
final String json = "{ \"" + keyName + "\" : 1 }";
final byte[] jsonAsBytes = json.getBytes(Data.UTF_8_CHARSET);
{
final JsonFactory jsonFactory = new JsonFactory();
final JacksonDataCodec codec = new JacksonDataCodec(jsonFactory);
// make sure intern field names is not enabled
assertFalse(jsonFactory.isEnabled(JsonFactory.Feature.INTERN_FIELD_NAMES));
assertTrue(jsonFactory.isEnabled(JsonFactory.Feature.CANONICALIZE_FIELD_NAMES));
final DataMap map = codec.bytesToMap(jsonAsBytes);
final String key = map.keySet().iterator().next();
assertNotSame(key, keyName);
}
{
final JsonFactory jsonFactory = new JsonFactory();
final JacksonDataCodec codec = new JacksonDataCodec(jsonFactory);
// enable intern field names
jsonFactory.enable(JsonFactory.Feature.INTERN_FIELD_NAMES);
assertTrue(jsonFactory.isEnabled(JsonFactory.Feature.INTERN_FIELD_NAMES));
assertTrue(jsonFactory.isEnabled(JsonFactory.Feature.CANONICALIZE_FIELD_NAMES));
final DataMap map = codec.bytesToMap(jsonAsBytes);
final String key = map.keySet().iterator().next();
assertSame(key, keyName);
}
}
use of com.fasterxml.jackson.core.JsonFactory in project pinpoint by naver.
the class AgentTimeHistogramTest method testViewModel.
@Test
public void testViewModel() throws IOException {
Application app = new Application("test", ServiceType.STAND_ALONE);
AgentTimeHistogramBuilder builder = new AgentTimeHistogramBuilder(app, new Range(0, 1000 * 60));
List<ResponseTime> responseHistogramList = createResponseTime(app, "test1", "test2");
AgentTimeHistogram histogram = builder.build(responseHistogramList);
List<AgentResponseTimeViewModel> viewModel = histogram.createViewModel();
logger.debug("{}", viewModel);
JsonFactory jsonFactory = mapper.getFactory();
StringWriter stringWriter = new StringWriter();
JsonGenerator jsonGenerator = jsonFactory.createGenerator(stringWriter);
jsonGenerator.writeStartObject();
for (AgentResponseTimeViewModel agentResponseTimeViewModel : viewModel) {
jsonGenerator.writeObject(agentResponseTimeViewModel);
}
jsonGenerator.writeEndObject();
jsonGenerator.flush();
jsonGenerator.close();
logger.debug(stringWriter.toString());
}
Aggregations