Skip to content
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 @@ -672,8 +672,22 @@ protected final JsonToken _nextToken2() throws IOException
f = _headContext.getFilter();
if ((f != null) && (f != TokenFilter.INCLUDE_ALL)) {
boolean includeEmpty = f.includeEmptyObject(_headContext.hasCurrentName());
// [core#1418]: If object is empty (start not handled), parent is an array,
// and parent wants to include empty arrays, include this empty object
// to preserve array structure
if (!includeEmpty && !returnEnd && _headContext._parent != null
&& _headContext._parent.inArray()) {
TokenFilter parentFilter = _headContext._parent.getFilter();
if ((parentFilter != null) && (parentFilter != TokenFilter.INCLUDE_ALL)) {
includeEmpty = parentFilter.includeEmptyArray(_headContext._parent.hasCurrentIndex());
}
}
f.filterFinishObject();
if (includeEmpty) {
_headContext._currentName = _headContext._parent == null
? null
: _headContext._parent._currentName;
_headContext._needToHandleName = false;
return _nextBuffered(_headContext);
} }
_headContext = _headContext.getParent();
Expand Down Expand Up @@ -847,6 +861,15 @@ protected final JsonToken _nextTokenWithBuffering(final TokenFilterContext buffR
f = _headContext.getFilter();
if ((f != null) && (f != TokenFilter.INCLUDE_ALL)) {
boolean includeEmpty = f.includeEmptyObject(_headContext.hasCurrentName());
// [core#1418]: If parent is an array and wants to include empty arrays,
// include this empty object to preserve array structure
if (!includeEmpty && _headContext._parent != null
&& _headContext._parent.inArray()) {
TokenFilter parentFilter = _headContext._parent.getFilter();
if ((parentFilter != null) && (parentFilter != TokenFilter.INCLUDE_ALL)) {
includeEmpty = parentFilter.includeEmptyArray(_headContext._parent.hasCurrentIndex());
}
}
f.filterFinishObject();
if (includeEmpty) {
_headContext._currentName = _headContext._parent == null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package com.fasterxml.jackson.core.tofix;
package com.fasterxml.jackson.core.filter;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.filter.FilteringParserDelegate;
import com.fasterxml.jackson.core.filter.TokenFilter;
import com.fasterxml.jackson.core.filter.TokenFilter.Inclusion;
import com.fasterxml.jackson.core.testutil.failure.JacksonTestFailureExpected;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
Expand Down Expand Up @@ -39,8 +36,7 @@ public boolean includeEmptyArray(boolean contentsFiltered) {

private final JsonFactory JSON_F = newStreamFactory();

// [core#1418]: case #1: failing
@JacksonTestFailureExpected
// [core#1418]: case #1
@Test
void filterArrayWithObjectsEndingWithFilteredProperty1() throws Exception
{
Expand Down