本文整理匯總了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.");
}
}