Skip to content

add null check for typeIdDef in LocalDateTimeSerializer #295

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,22 @@ public void serializeWithType(LocalDate value, JsonGenerator g,
{
WritableTypeId typeIdDef = typeSer.writeTypePrefix(g,
typeSer.typeId(value, serializationShape(provider)));
// need to write out to avoid double-writing array markers
switch (typeIdDef.valueShape) {
case START_ARRAY:
_serializeAsArrayContents(value, g, provider);
break;
case VALUE_NUMBER_INT:
g.writeNumber(value.toEpochDay());
break;
default:
g.writeString((_formatter == null) ? value.toString() : value.format(_formatter));
if (typeIdDef == null) {
serialize(value, g, provider);
} else {
// need to write out to avoid double-writing array markers
switch (typeIdDef.valueShape) {
case START_ARRAY:
_serializeAsArrayContents(value, g, provider);
break;
case VALUE_NUMBER_INT:
g.writeNumber(value.toEpochDay());
break;
default:
g.writeString((_formatter == null) ? value.toString() : value.format(_formatter));
}
typeSer.writeTypeSuffix(g, typeIdDef);
}
typeSer.writeTypeSuffix(g, typeIdDef);
}

protected void _serializeAsArrayContents(LocalDate value, JsonGenerator g,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,21 @@ public void serializeWithType(LocalDateTime value, JsonGenerator g, SerializerPr
{
WritableTypeId typeIdDef = typeSer.writeTypePrefix(g,
typeSer.typeId(value, serializationShape(provider)));
// need to write out to avoid double-writing array markers
if (typeIdDef.valueShape == JsonToken.START_ARRAY) {
_serializeAsArrayContents(value, g, provider);
if (typeIdDef == null) {
serialize(value, g, provider);
} else {
DateTimeFormatter dtf = _formatter;
if (dtf == null) {
dtf = _defaultFormatter();
// need to write out to avoid double-writing array markers
if (typeIdDef.valueShape == JsonToken.START_ARRAY) {
_serializeAsArrayContents(value, g, provider);
} else {
DateTimeFormatter dtf = _formatter;
if (dtf == null) {
dtf = _defaultFormatter();
}
g.writeString(value.format(dtf));
}
g.writeString(value.format(dtf));
typeSer.writeTypeSuffix(g, typeIdDef);
}
typeSer.writeTypeSuffix(g, typeIdDef);
}

private final void _serializeAsArrayContents(LocalDateTime value, JsonGenerator g,
Expand Down