本文整理汇总了Java中com.fasterxml.jackson.databind.DeserializationContext.wrongTokenException方法的典型用法代码示例。如果您正苦于以下问题:Java DeserializationContext.wrongTokenException方法的具体用法?Java DeserializationContext.wrongTokenException怎么用?Java DeserializationContext.wrongTokenException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.fasterxml.jackson.databind.DeserializationContext
的用法示例。
在下文中一共展示了DeserializationContext.wrongTokenException方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deserialize
import com.fasterxml.jackson.databind.DeserializationContext; //导入方法依赖的package包/类
@Override
public LocalDateTime deserialize(JsonParser parser, DeserializationContext context) throws IOException
{
if (parser.hasTokenId(JsonTokenId.ID_STRING)) {
String string = parser.getText().trim();
if (string.length() == 0) {
return null;
}
try {
return LocalDateTime.parse(string, DateTimeFormatter.ISO_LOCAL_DATE_TIME);
} catch (DateTimeException e) {
throw new IOException(e);
}
}
if (parser.hasTokenId(JsonTokenId.ID_EMBEDDED_OBJECT)) {
return (LocalDateTime) parser.getEmbeddedObject();
}
throw context.wrongTokenException(parser, JsonToken.VALUE_STRING, "Expected string.");
}
示例2: deserialize
import com.fasterxml.jackson.databind.DeserializationContext; //导入方法依赖的package包/类
@Override
public LocalDate deserialize(JsonParser parser, DeserializationContext context) throws IOException
{
if (parser.hasTokenId(JsonTokenId.ID_STRING)) {
String string = parser.getText().trim();
if (string.length() == 0) {
return null;
}
try {
return LocalDate.parse(string, DateTimeFormatter.ISO_LOCAL_DATE);
} catch (DateTimeException e) {
throw new IOException(e);
}
}
if (parser.hasTokenId(JsonTokenId.ID_EMBEDDED_OBJECT)) {
return (LocalDate) parser.getEmbeddedObject();
}
throw context.wrongTokenException(parser, JsonToken.VALUE_STRING, "Expected string.");
}
示例3: deserialize
import com.fasterxml.jackson.databind.DeserializationContext; //导入方法依赖的package包/类
@Override
public LocalDate deserialize(JsonParser parser, DeserializationContext context) throws IOException {
switch(parser.getCurrentToken()) {
case START_ARRAY:
if(parser.nextToken() == JsonToken.END_ARRAY) {
return null;
}
int year = parser.getIntValue();
parser.nextToken();
int month = parser.getIntValue();
parser.nextToken();
int day = parser.getIntValue();
if(parser.nextToken() != JsonToken.END_ARRAY) {
throw context.wrongTokenException(parser, JsonToken.END_ARRAY, "Expected array to end.");
}
return LocalDate.of(year, month, day);
case VALUE_STRING:
String string = parser.getText().trim();
if(string.length() == 0) {
return null;
}
return LocalDate.parse(string, ISO_DATE_OPTIONAL_TIME);
}
throw context.wrongTokenException(parser, JsonToken.START_ARRAY, "Expected array or string.");
}
示例4: deserialize
import com.fasterxml.jackson.databind.DeserializationContext; //导入方法依赖的package包/类
@Override
public LocalDate deserialize(JsonParser parser, DeserializationContext context) throws IOException {
switch(parser.getCurrentToken()) {
case START_ARRAY:
if(parser.nextToken() == JsonToken.END_ARRAY) {
return null;
}
int year = parser.getIntValue();
parser.nextToken();
int month = parser.getIntValue();
parser.nextToken();
int day = parser.getIntValue();
if(parser.nextToken() != JsonToken.END_ARRAY) {
throw context.wrongTokenException(parser, JsonToken.END_ARRAY, "Expected array to end.");
}
return LocalDate.of(year, month, day);
case VALUE_STRING:
String string = parser.getText().trim();
if(string.length() == 0) {
return null;
}
return LocalDate.parse(string, ISO_DATE_OPTIONAL_TIME);
default:
throw context.wrongTokenException(parser, JsonToken.START_ARRAY, "Expected array or string.");
}
}