diff --git a/log4j2-elasticsearch-core/src/main/java/com/fasterxml/jackson/core/JsonStreamContextAccessor.java b/log4j2-elasticsearch-core/src/main/java/com/fasterxml/jackson/core/JsonStreamContextAccessor.java deleted file mode 100644 index 09573cc8..00000000 --- a/log4j2-elasticsearch-core/src/main/java/com/fasterxml/jackson/core/JsonStreamContextAccessor.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.fasterxml.jackson.core; - -/*- - * #%L - * log4j2-elasticsearch - * %% - * Copyright (C) 2020 Rafal Foltynski - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -/** - * Helper class to allow {@code com.fasterxml.jackson.core.JsonStreamContext} state access. - */ -public class JsonStreamContextAccessor { - - public static final int TYPE_ROOT = JsonStreamContext.TYPE_ROOT; - - public int getType(JsonStreamContext ctx) { - return ctx._type; - } - -} diff --git a/log4j2-elasticsearch-core/src/main/java/com/fasterxml/jackson/core/json/JsonWriteContextAccessor.java b/log4j2-elasticsearch-core/src/main/java/org/appenders/log4j2/elasticsearch/JsonWriteContextAccessor.java similarity index 76% rename from log4j2-elasticsearch-core/src/main/java/com/fasterxml/jackson/core/json/JsonWriteContextAccessor.java rename to log4j2-elasticsearch-core/src/main/java/org/appenders/log4j2/elasticsearch/JsonWriteContextAccessor.java index efa8088c..ce07835c 100644 --- a/log4j2-elasticsearch-core/src/main/java/com/fasterxml/jackson/core/json/JsonWriteContextAccessor.java +++ b/log4j2-elasticsearch-core/src/main/java/org/appenders/log4j2/elasticsearch/JsonWriteContextAccessor.java @@ -1,4 +1,4 @@ -package com.fasterxml.jackson.core.json; +package org.appenders.log4j2.elasticsearch; /*- * #%L @@ -20,17 +20,15 @@ * #L% */ -import com.fasterxml.jackson.core.JsonStreamContextAccessor; +import com.fasterxml.jackson.core.json.JsonWriteContext; -import static com.fasterxml.jackson.core.JsonStreamContextAccessor.TYPE_ROOT; +import static com.fasterxml.jackson.core.JsonStreamContext.TYPE_ROOT; /** * Helper class to allow {@code com.fasterxml.jackson.core.json.JsonWriteContext} state access. */ public class JsonWriteContextAccessor { - private final JsonStreamContextAccessor streamCtxAccess = new JsonStreamContextAccessor(); - public JsonWriteContext reset(JsonWriteContext ctx) { if (ctx.getParent() == null) { @@ -46,8 +44,8 @@ public JsonWriteContext reset(JsonWriteContext ctx) { return parent.reset(TYPE_ROOT); } - int getType(JsonWriteContext ctx) { - return streamCtxAccess.getType(ctx); + /* visible for testing */ + boolean inRoot(JsonWriteContext ctxAfterReset) { + return ctxAfterReset.inRoot(); } - } diff --git a/log4j2-elasticsearch-core/src/main/java/org/appenders/log4j2/elasticsearch/ReusableUTF8JsonGenerator.java b/log4j2-elasticsearch-core/src/main/java/org/appenders/log4j2/elasticsearch/ReusableUTF8JsonGenerator.java index 10ce4904..58f36ddb 100644 --- a/log4j2-elasticsearch-core/src/main/java/org/appenders/log4j2/elasticsearch/ReusableUTF8JsonGenerator.java +++ b/log4j2-elasticsearch-core/src/main/java/org/appenders/log4j2/elasticsearch/ReusableUTF8JsonGenerator.java @@ -23,7 +23,6 @@ import com.fasterxml.jackson.core.JsonStreamContext; import com.fasterxml.jackson.core.ObjectCodec; import com.fasterxml.jackson.core.io.IOContext; -import com.fasterxml.jackson.core.json.JsonWriteContextAccessor; import com.fasterxml.jackson.core.json.UTF8JsonGenerator; import java.io.IOException; diff --git a/log4j2-elasticsearch-core/src/main/java/org/appenders/log4j2/elasticsearch/SingleThreadJsonFactory.java b/log4j2-elasticsearch-core/src/main/java/org/appenders/log4j2/elasticsearch/SingleThreadJsonFactory.java index c8cd9a76..e37ec172 100644 --- a/log4j2-elasticsearch-core/src/main/java/org/appenders/log4j2/elasticsearch/SingleThreadJsonFactory.java +++ b/log4j2-elasticsearch-core/src/main/java/org/appenders/log4j2/elasticsearch/SingleThreadJsonFactory.java @@ -26,7 +26,6 @@ import com.fasterxml.jackson.core.ObjectCodec; import com.fasterxml.jackson.core.io.CharacterEscapes; import com.fasterxml.jackson.core.io.IOContext; -import com.fasterxml.jackson.core.json.JsonWriteContextAccessor; import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; import java.io.DataOutput; diff --git a/log4j2-elasticsearch-core/src/test/java/com/fasterxml/jackson/core/json/ReusableUTF8JsonGeneratorTest.java b/log4j2-elasticsearch-core/src/test/java/com/fasterxml/jackson/core/json/ReusableUTF8JsonGeneratorTest.java index 8093e5ba..bd0e66b9 100644 --- a/log4j2-elasticsearch-core/src/test/java/com/fasterxml/jackson/core/json/ReusableUTF8JsonGeneratorTest.java +++ b/log4j2-elasticsearch-core/src/test/java/com/fasterxml/jackson/core/json/ReusableUTF8JsonGeneratorTest.java @@ -23,6 +23,7 @@ import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.util.BufferRecycler; import com.fasterxml.jackson.databind.ObjectMapper; +import org.appenders.log4j2.elasticsearch.JsonWriteContextAccessor; import org.appenders.log4j2.elasticsearch.OutputStreamDelegate; import org.appenders.log4j2.elasticsearch.ReusableIOContext; import org.appenders.log4j2.elasticsearch.ReusableUTF8JsonGenerator; diff --git a/log4j2-elasticsearch-core/src/test/java/com/fasterxml/jackson/core/json/JsonWriteContextAccessorTest.java b/log4j2-elasticsearch-core/src/test/java/org/appenders/log4j2/elasticsearch/JsonWriteContextAccessorTest.java similarity index 69% rename from log4j2-elasticsearch-core/src/test/java/com/fasterxml/jackson/core/json/JsonWriteContextAccessorTest.java rename to log4j2-elasticsearch-core/src/test/java/org/appenders/log4j2/elasticsearch/JsonWriteContextAccessorTest.java index 2a618817..1e98fde3 100644 --- a/log4j2-elasticsearch-core/src/test/java/com/fasterxml/jackson/core/json/JsonWriteContextAccessorTest.java +++ b/log4j2-elasticsearch-core/src/test/java/org/appenders/log4j2/elasticsearch/JsonWriteContextAccessorTest.java @@ -1,4 +1,4 @@ -package com.fasterxml.jackson.core.json; +package org.appenders.log4j2.elasticsearch; /*- * #%L @@ -20,12 +20,12 @@ * #L% */ +import com.fasterxml.jackson.core.json.JsonWriteContext; import org.junit.Test; -import static com.fasterxml.jackson.core.JsonStreamContextAccessor.TYPE_ROOT; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; public class JsonWriteContextAccessorTest { @@ -34,14 +34,14 @@ public void resetResetsCurrentContextImmediatelyIfContextHasNoParent() { // given JsonWriteContextAccessor ctxAccess = new JsonWriteContextAccessor(); - JsonWriteContext context = new JsonWriteContext(TYPE_ROOT, null, null); + JsonWriteContext context = JsonWriteContext.createRootContext(null); // when JsonWriteContext ctxAfterReset = ctxAccess.reset(context); // then assertSame(context, ctxAfterReset); - assertEquals(ctxAccess.getType(ctxAfterReset), TYPE_ROOT); + assertTrue(ctxAccess.inRoot(ctxAfterReset)); } @@ -50,21 +50,18 @@ public void resetResetsAndReturnsRootContextIfContextHasParent() { // given JsonWriteContextAccessor ctxAccess = new JsonWriteContextAccessor(); - JsonWriteContext grandpaContext = new JsonWriteContext(TYPE_ROOT, null, null); + JsonWriteContext grandpaContext = JsonWriteContext.createRootContext(null); JsonWriteContext parentContext = grandpaContext.createChildObjectContext(); JsonWriteContext childContext = parentContext.createChildObjectContext(); - int childContextType = ctxAccess.getType(childContext); - - assertNotEquals(ctxAccess.getType(childContext), TYPE_ROOT); + assertFalse(ctxAccess.inRoot(childContext)); // when JsonWriteContext ctxAfterReset = ctxAccess.reset(childContext); // then assertSame(grandpaContext, ctxAfterReset); - assertEquals(TYPE_ROOT, ctxAccess.getType(ctxAfterReset)); - assertEquals(childContextType, ctxAccess.getType(childContext)); + assertTrue(ctxAccess.inRoot(ctxAfterReset)); }