本文整理汇总了Java中com.fasterxml.jackson.core.JsonGenerator类的典型用法代码示例。如果您正苦于以下问题:Java JsonGenerator类的具体用法?Java JsonGenerator怎么用?Java JsonGenerator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JsonGenerator类属于com.fasterxml.jackson.core包,在下文中一共展示了JsonGenerator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeMetaData
import com.fasterxml.jackson.core.JsonGenerator; //导入依赖的package包/类
@Override
public void writeMetaData(OutputStream out, ResourceWithMetadata resource, Map<String, ResourceWithMetadata> allApiResources) throws IOException
{
final Object result = processResult(resource,allApiResources);
assistant.getJsonHelper().withWriter(out, new Writer()
{
@Override
public void writeContents(JsonGenerator generator, ObjectMapper objectMapper)
throws JsonGenerationException, JsonMappingException, IOException
{
objectMapper.writeValue(generator, result);
}
});
}
示例2: serialize
import com.fasterxml.jackson.core.JsonGenerator; //导入依赖的package包/类
@Override
public void serialize(CategoryLines categoryLines,
JsonGenerator jgen,
SerializerProvider provider) throws
IOException,
JsonProcessingException {
jgen.writeStartObject();
super.serialize(categoryLines, jgen, provider);
if (categoryLines.getWidth() != null) {
jgen.writeObjectField("width", categoryLines.getWidth());
}
if (categoryLines.getStyles() != null) {
jgen.writeObjectField("styles", categoryLines.getStyles());
} else {
jgen.writeObjectField("style", categoryLines.getStyle().toString());
}
if (categoryLines.getInterpolation() != null) {
jgen.writeObjectField("interpolation", categoryLines.getInterpolation());
}
jgen.writeEndObject();
}
示例3: writeHistorieRecordKop
import com.fasterxml.jackson.core.JsonGenerator; //导入依赖的package包/类
private void writeHistorieRecordKop(final JsonGenerator jgen, final BlobViewGroep groep) throws IOException {
jgen.writeArrayFieldStart("kolomtitels");
jgen.writeString(INDEX_OBJECT);
if (isFormeel(groep.getElement())) {
jgen.writeString(TIJDSTIP_REGISTRATIE);
jgen.writeString(TIJDSTIP_VERVAL);
jgen.writeString(NADERE_AANDUIDING_VERVAL);
jgen.writeString(ActieType.INHOUD.getOmschrijving());
jgen.writeString(ActieType.VERVAL.getOmschrijving());
jgen.writeString(CSS);
} else if (isMaterieel(groep.getElement())) {
jgen.writeString(DATUM_INGANG_GELDIGHEID);
jgen.writeString(DATUM_EINDE_GELDIGHEID);
jgen.writeString(TIJDSTIP_REGISTRATIE);
jgen.writeString(TIJDSTIP_VERVAL);
jgen.writeString(NADERE_AANDUIDING_VERVAL);
jgen.writeString(ActieType.INHOUD.getOmschrijving());
jgen.writeString(ActieType.AANPASSING.getOmschrijving());
jgen.writeString(ActieType.VERVAL.getOmschrijving());
jgen.writeString(CSS);
}
jgen.writeString(DETAIL);
jgen.writeEndArray();
}
示例4: serialize
import com.fasterxml.jackson.core.JsonGenerator; //导入依赖的package包/类
protected void serialize(T chart, JsonGenerator jgen) throws IOException {
super.serialize(chart, jgen);
String type = chart.getClass().getSimpleName();
if ("SimpleTimePlot".equals(type)){
jgen.writeObjectField("type", "TimePlot");
}else {
jgen.writeObjectField("type", type);
}
jgen.writeObjectField(INIT_WIDTH, chart.getInitWidth());
jgen.writeObjectField(INIT_HEIGHT, chart.getInitHeight());
jgen.writeObjectField(CHART_TITLE, chart.getTitle());
jgen.writeObjectField(SHOW_LEGEND, chart.getShowLegend());
jgen.writeObjectField(USE_TOOL_TIP, chart.getUseToolTip());
jgen.writeObjectField(LEGEND_POSITION, chart.getLegendPosition());
jgen.writeObjectField("legend_layout", chart.getLegendLayout());
jgen.writeObjectField("custom_styles", chart.getCustomStyles());
jgen.writeObjectField("element_styles", chart.getElementStyles());
}
示例5: configureFeature
import com.fasterxml.jackson.core.JsonGenerator; //导入依赖的package包/类
private void configureFeature(ObjectMapper objectMapper, Object feature, boolean enabled) {
if (feature instanceof JsonParser.Feature) {
objectMapper.configure((JsonParser.Feature) feature, enabled);
}
else if (feature instanceof JsonGenerator.Feature) {
objectMapper.configure((JsonGenerator.Feature) feature, enabled);
}
else if (feature instanceof SerializationFeature) {
objectMapper.configure((SerializationFeature) feature, enabled);
}
else if (feature instanceof DeserializationFeature) {
objectMapper.configure((DeserializationFeature) feature, enabled);
}
else if (feature instanceof MapperFeature) {
objectMapper.configure((MapperFeature) feature, enabled);
}
else {
throw new FatalBeanException("Unknown feature class: " + feature.getClass().getName());
}
}
示例6: serialize
import com.fasterxml.jackson.core.JsonGenerator; //导入依赖的package包/类
@Override
public void serialize(JsonMeter jsonMeter,
JsonGenerator json,
SerializerProvider provider) throws IOException {
json.writeStartObject();
json.writeStringField("name", jsonMeter.name());
json.writeObjectField(timestampFieldname, jsonMeter.timestampAsDate());
Meter meter = jsonMeter.value();
json.writeNumberField("count", meter.getCount());
json.writeNumberField("m1_rate", meter.getOneMinuteRate() * rateFactor);
json.writeNumberField("m5_rate", meter.getFiveMinuteRate() * rateFactor);
json.writeNumberField("m15_rate", meter.getFifteenMinuteRate() * rateFactor);
json.writeNumberField("mean_rate", meter.getMeanRate() * rateFactor);
json.writeStringField("units", rateUnit);
addOneOpsMetadata(json);
json.writeEndObject();
}
示例7: serialize
import com.fasterxml.jackson.core.JsonGenerator; //导入依赖的package包/类
@Override
public void serialize(final TradingStatusType value, final JsonGenerator gen, final SerializerProvider serializers) throws IOException {
if (value == null || value == TradingStatusType.UNKNOWN) {
gen.writeNull();
return;
}
switch (value) {
case TRADING_HALTED:
gen.writeString("H");
break;
case TRADING_HALT_RELEASED_INTO_ORDER_ACCEPTANCE_PERIOD:
gen.writeString("O");
break;
case TRADING_PAUSED_AND_ORDER_ACCEPTANCE_PERIOD_ON_IEX:
gen.writeString("P");
break;
case TRADING_ON_IEX:
gen.writeString("T");
break;
default:
gen.writeNull();
break;
}
}
示例8: _testFailOnWritingStringFromReaderWithTooFewCharacters
import com.fasterxml.jackson.core.JsonGenerator; //导入依赖的package包/类
private void _testFailOnWritingStringFromReaderWithTooFewCharacters(JsonFactory f, boolean useReader) throws Exception{
JsonGenerator gen;
ByteArrayOutputStream bout = new ByteArrayOutputStream();
if (useReader) {
gen = f.createGenerator(ObjectWriteContext.empty(), new OutputStreamWriter(bout, "UTF-8"));
} else {
gen = f.createGenerator(ObjectWriteContext.empty(), bout, JsonEncoding.UTF8);
}
gen.writeStartObject();
try {
String testStr = "aaaaaaaaa";
StringReader reader = new StringReader(testStr);
gen.writeFieldName("a");
gen.writeString(reader, testStr.length() + 1);
gen.flush();
String json = bout.toString("UTF-8");
fail("Should not have let "+gen.getClass().getName()+".writeString() ': output = "+json);
} catch (JsonProcessingException e) {
verifyException(e, "Didn't read enough from reader");
}
gen.close();
}
示例9: serialize
import com.fasterxml.jackson.core.JsonGenerator; //导入依赖的package包/类
@Override
public void serialize(JsonGenerator generator) throws IOException {
generator.writeNumber(getCode());
generator.writeNumber(this.sessionId);
generator.writeStartObject();
generator.writeObjectFieldStart("roles");
for (WampRole wampRole : this.roles) {
generator.writeObjectFieldStart(wampRole.getRole());
if (wampRole.hasFeatures()) {
generator.writeObjectFieldStart("features");
for (String feature : wampRole.getFeatures()) {
generator.writeBooleanField(feature, true);
}
generator.writeEndObject();
}
generator.writeEndObject();
}
generator.writeEndObject();
if (this.realm != null) {
generator.writeStringField("realm", this.realm);
}
generator.writeEndObject();
}
示例10: serialize
import com.fasterxml.jackson.core.JsonGenerator; //导入依赖的package包/类
@Override
public void serialize(final BerichtListView value, final JsonGenerator jgen, final SerializerProvider provider) throws IOException {
jgen.writeStartObject();
if (value.getBericht() != null) {
JsonUtils.writeAsInteger(jgen, BerichtModule.ID, ObjectUtils.getWaarde(value, "bericht.id"));
JsonUtils.writeAsInteger(jgen, BerichtModule.SOORT, ObjectUtils.getWaarde(value, "bericht.soortBericht.id"));
JsonUtils.writeAsInteger(jgen, BerichtModule.ZENDENDE_PARTIJ, ObjectUtils.getWaarde(value, "bericht.zendendePartij"));
JsonUtils.writeAsInteger(jgen, BerichtModule.ONTVANGENDE_PARTIJ, ObjectUtils.getWaarde(value, "bericht.ontvangendePartij"));
JsonUtils.writeAsString(jgen, BerichtModule.REFERENTIENUMMER, value.getBericht().getReferentieNummer());
JsonUtils.writeAsString(jgen, BerichtModule.CROSS_REFERENTIENUMMER, value.getBericht().getCrossReferentieNummer());
JsonUtils.writeAsString(jgen, BerichtModule.VERZENDDATUM, ObjectUtils.getGeformateerdeWaarde(value, "bericht.datumTijdVerzending", sdf));
JsonUtils.writeAsString(jgen, BerichtModule.ONTVANGSTDATUM, ObjectUtils.getGeformateerdeWaarde(value, "bericht.datumTijdOntvangst", sdf));
JsonUtils.writeAsInteger(jgen, BerichtModule.SOORT_SYNCHRONISATIE, ObjectUtils.getWaarde(value, "bericht.soortSynchronisatie.id"));
JsonUtils.writeAsInteger(jgen, BerichtModule.VERWERKINGSWIJZE, ObjectUtils.getWaarde(value, "bericht.verwerkingswijze.id"));
JsonUtils.writeAsInteger(jgen, BerichtModule.BIJHOUDING, ObjectUtils.getWaarde(value, "bericht.bijhoudingResultaat.id"));
}
jgen.writeEndObject();
}
示例11: maakCssLinkObject
import com.fasterxml.jackson.core.JsonGenerator; //导入依赖的package包/类
private void maakCssLinkObject(final ActieType actieType, final BlobViewObject actie, final StringBuilder ccsClassBuilder, final JsonGenerator jgen)
throws IOException {
if (actie != null) {
final BlobViewObject administratieveHandeling = actie.getParent();
ccsClassBuilder.append(BRP_MARKEER);
ccsClassBuilder.append(administratieveHandeling.getObjectsleutel());
ccsClassBuilder.append(" ");
jgen.writeObjectFieldStart(actieType.getOmschrijving());
jgen.writeStringField(TYPE, CSS_LINK);
jgen.writeStringField(LINK_TEKST, "Ja (actie " + actie.getObjectsleutel() + ")");
jgen.writeStringField(LINK, BRP_MARKEER + administratieveHandeling.getObjectsleutel());
jgen.writeEndObject();
} else {
jgen.writeObjectFieldStart(actieType.getOmschrijving());
jgen.writeStringField(TYPE, CSS_LINK);
jgen.writeStringField(LINK_TEKST, "Nee");
jgen.writeStringField(LINK, "");
jgen.writeEndObject();
}
}
示例12: serialize
import com.fasterxml.jackson.core.JsonGenerator; //导入依赖的package包/类
@Override
public void serialize(final Version value, final JsonGenerator jgen, final SerializerProvider provider) throws IOException {
jgen.writeStartObject();
writeVersieRegel(jgen, value.getMainVersion());
jgen.writeArrayFieldStart(VersieModule.COMPONENTEN);
for (final VersionLine component : value.getComponentVersions()) {
jgen.writeStartObject();
writeVersieRegel(jgen, component);
jgen.writeEndObject();
}
jgen.writeEndArray();
jgen.writeEndObject();
}
示例13: serialize
import com.fasterxml.jackson.core.JsonGenerator; //导入依赖的package包/类
@Override
public void serialize(JsonGenerator generator) throws IOException {
generator.writeNumber(getCode());
generator.writeNumber(this.requestId);
generator.writeStartObject();
generator.writeEndObject();
if (this.argumentsKw != null) {
if (this.arguments == null) {
generator.writeStartArray();
generator.writeEndArray();
}
else {
generator.writeObject(this.arguments);
}
generator.writeObject(this.argumentsKw);
}
else if (this.arguments != null) {
generator.writeObject(this.arguments);
}
}
示例14: serialize
import com.fasterxml.jackson.core.JsonGenerator; //导入依赖的package包/类
@Override
public void serialize(LinksInformation value, JsonGenerator gen, SerializerProvider serializers)
throws IOException {
gen.writeStartObject();
BeanInformation info = BeanInformation.get(value.getClass());
for (String attrName : info.getAttributeNames()) {
BeanAttributeInformation attribute = info.getAttribute(attrName);
Object linkValue = attribute.getValue(value);
if (linkValue != null) {
gen.writeObjectFieldStart(attrName);
if (linkValue instanceof String) {
gen.writeStringField(SerializerUtil.HREF, linkValue.toString());
}
else {
gen.writeObject(linkValue);
}
gen.writeEndObject();
}
}
gen.writeEndObject();
}
示例15: serialize
import com.fasterxml.jackson.core.JsonGenerator; //导入依赖的package包/类
@Override
public void serialize(Wrapper<?> value, JsonGenerator gen, SerializerProvider provider) throws IOException {
// TODO: maybe find a cleaner way to do this
if(Vector.class.isAssignableFrom(value.getWrappedClass())) {
// value is a vector, just write the coordinates
gen.writeObject(((Vector) value.getWrapped()).toArray());
return;
}
gen.writeStartObject();
gen.writeStringField("class", value.getWrappedClass().getSimpleName());
gen.writeNumberField("id", value.getWrappedId());
value.getValues().forEach((name, obj) -> {
try {
gen.writeObjectField(name, obj);
} catch (IOException e) {
e.printStackTrace();
}
});
// for(Property p : value.getProperties()) {
// gen.writeObjectField(p.getName(), p);
// }
gen.writeEndObject();
}