本文整理汇总了Java中com.fasterxml.jackson.core.JsonGenerator.writeBoolean方法的典型用法代码示例。如果您正苦于以下问题:Java JsonGenerator.writeBoolean方法的具体用法?Java JsonGenerator.writeBoolean怎么用?Java JsonGenerator.writeBoolean使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.fasterxml.jackson.core.JsonGenerator
的用法示例。
在下文中一共展示了JsonGenerator.writeBoolean方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: serialize
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
@Override
public void serialize(Object value, JsonGenerator generator, boolean writeStartAndEnd) throws IOException {
if (value == null) {
generator.writeNull();
} else if (value instanceof String) {
generator.writeString((String)value);
} else if (value instanceof Integer) {
generator.writeNumber((Integer)value);
} else if (value instanceof Long) {
generator.writeNumber((Long)value);
} else if (value instanceof Float) {
generator.writeNumber((Float)value);
} else if (value instanceof Double) {
generator.writeNumber((Double)value);
} else if (value instanceof Boolean) {
generator.writeBoolean((Boolean)value);
} else if (value instanceof List) {
LoganSquare.mapperFor(List.class).serialize((List<Object>)value, generator, writeStartAndEnd);
} else if (value instanceof Map) {
LoganSquare.mapperFor(Map.class).serialize((Map<String, Object>)value, generator, writeStartAndEnd);
} else {
Class valueClass = value.getClass();
JsonMapper jsonMapper = LoganSquare.mapperFor(valueClass);
if (jsonMapper != null) {
if (writeStartAndEnd) {
generator.writeStartObject();
}
jsonMapper.serialize(value, generator, false);
if (writeStartAndEnd) {
generator.writeEndObject();
}
}
}
}
示例2: serialize
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
@Override
public void serialize(T object, String fieldName, boolean writeFieldNameForObject, JsonGenerator jsonGenerator) throws IOException {
if (fieldName != null) {
jsonGenerator.writeBooleanField(fieldName, convertToBoolean(object));
} else {
jsonGenerator.writeBoolean(convertToBoolean(object));
}
}
示例3: processValue
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
/**
* Uses a JsonToken + JsonParser to determine how to write a value to the JsonGenerator.
*
* <p>This separation exists so we can separate the iteration logic from the parsing logic.
*
* @param valueToken current token we are interested in from the parser
* @param parser current parser
* @param jgen JsonGenerator that is used for writing json onto an underlying stream
* @throws JsonGenerationException if access to the JsonParser throws a JsonGenerationException
* @throws IOException if the Jackson utilties (JsonParser or JsonGenerator) throw an IOException
*/
private void processValue(JsonToken valueToken, JsonParser parser, JsonGenerator jgen)
throws IOException {
if (valueToken.isBoolean()) {
jgen.writeBoolean(parser.getBooleanValue());
} else if (valueToken.isNumeric()) {
if (parser.getNumberType() == JsonParser.NumberType.INT) {
jgen.writeNumber(parser.getIntValue());
} else if (parser.getNumberType() == JsonParser.NumberType.DOUBLE) {
jgen.writeNumber(parser.getDoubleValue());
} else if (parser.getNumberType() == JsonParser.NumberType.FLOAT) {
jgen.writeNumber(parser.getFloatValue());
} else if (parser.getNumberType() == JsonParser.NumberType.LONG) {
jgen.writeNumber(parser.getLongValue());
} else if (parser.getNumberType() == JsonParser.NumberType.BIG_DECIMAL) {
jgen.writeNumber(parser.getDecimalValue());
} else if (parser.getNumberType() == JsonParser.NumberType.BIG_INTEGER) {
jgen.writeNumber(parser.getBigIntegerValue());
} else {
LOGGER.error("Found unsupported numeric value with name {}.", parser.getCurrentName());
throw new RuntimeException(
"Found unsupported numeric value with name " + parser.getCurrentName());
}
} else if (valueToken.id() == JsonTokenId.ID_STRING) {
jgen.writeString(parser.getText());
} else {
// Something bad just happened. Probably an unsupported type.
LOGGER.error(
"Found unsupported value type {} for name {}.", valueToken.id(), parser.getCurrentName());
throw new RuntimeException(
"Found unsupported value type " + valueToken.id() + " for name " + parser
.getCurrentName());
}
}
示例4: getJsonFromPrimitiveBoolArray
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
public static void getJsonFromPrimitiveBoolArray(JsonGenerator jg, boolean[] array, String pf)
throws JsonGenerationException, IOException {
jg.writeStartArray();
for (boolean obj : array) {
jg.writeBoolean(obj);
}
jg.writeEndArray();
}
示例5: getJsonFromWrapperBoolArray
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
public static void getJsonFromWrapperBoolArray(JsonGenerator jg, Boolean[] array, String pf)
throws JsonGenerationException, IOException {
jg.writeStartArray();
for (Boolean obj : array) {
jg.writeBoolean(obj.booleanValue());
}
jg.writeEndArray();
}
示例6: serialize
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
@Override
public void serialize(Boolean object, JsonGenerator generator, boolean writeStartAndEnd) throws IOException {
generator.writeBoolean(object);
}
示例7: printFieldValue
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
private void printFieldValue(FieldDescriptor field, Object value, JsonGenerator generator) throws IOException {
// TODO: look at using field.getType().getJavaType(), to simplify this..
switch (field.getType()) {
case INT32:
case SINT32:
case SFIXED32:
generator.writeNumber((Integer)value);
break;
case INT64:
case SINT64:
case SFIXED64:
generator.writeNumber((Long)value);
break;
case FLOAT:
generator.writeNumber((Float)value);
break;
case DOUBLE:
generator.writeNumber((Double)value);
break;
case BOOL:
// Good old toString() does what we want for these types.
generator.writeBoolean((Boolean)value);
break;
case UINT32:
case FIXED32:
generator.writeNumber(Integer.toUnsignedLong((Integer)value));
break;
case UINT64:
case FIXED64:
generator.writeNumber(unsignedLong((Long) value));
break;
case STRING:
generator.writeString((String) value);
break;
case BYTES: {
// Here we break with JsonFormat - since there is an issue with non-utf8 bytes..
generator.writeBinary(((ByteString)value).toByteArray());
break;
}
case ENUM: {
generator.writeString(((EnumValueDescriptor) value).getName());
break;
}
case MESSAGE:
case GROUP:
generator.writeStartObject();
printMessage((Message) value, generator);
generator.writeEndObject();
break;
}
}
示例8: printBool
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
static void printBool(boolean value, JsonGenerator gen) throws IOException {
gen.writeBoolean(value);
}
示例9: write
import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
void write(JsonGenerator json, HashSet visited) throws Exception
{
json.writeStartArray();
for (Object obj : objects)
{
if (obj == null)
{
json.writeNull();
}
else if (obj instanceof JSObject)
{
((JSObject) obj).write(json, visited);
}
else if (obj instanceof BigDecimal)
{
json.writeNumber((BigDecimal) obj);
}
else if (obj instanceof Double)
{
json.writeNumber((Double) obj);
}
else if (obj instanceof Float)
{
json.writeNumber((Float) obj);
}
else if (obj instanceof Integer)
{
json.writeNumber((Integer) obj);
}
else if (obj instanceof Long)
{
json.writeNumber((Long) obj);
}
else if (obj instanceof BigDecimal)
{
json.writeNumber((BigDecimal) obj);
}
else if (obj instanceof BigDecimal)
{
json.writeNumber((BigDecimal) obj);
}
else if (obj instanceof Boolean)
{
json.writeBoolean((Boolean) obj);
}
else
{
json.writeString(obj + "");
}
}
json.writeEndArray();
}