Skip to content

Commit 63cf944

Browse files
committed
Repackaging of Jackson FasterXML package-private classes (#56)
* Cleanup before module extraction
1 parent 8b22a62 commit 63cf944

File tree

6 files changed

+16
-56
lines changed

6 files changed

+16
-56
lines changed

log4j2-elasticsearch-core/src/main/java/com/fasterxml/jackson/core/JsonStreamContextAccessor.java

-34
This file was deleted.

log4j2-elasticsearch-core/src/main/java/com/fasterxml/jackson/core/json/JsonWriteContextAccessor.java renamed to log4j2-elasticsearch-core/src/main/java/org/appenders/log4j2/elasticsearch/JsonWriteContextAccessor.java

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.fasterxml.jackson.core.json;
1+
package org.appenders.log4j2.elasticsearch;
22

33
/*-
44
* #%L
@@ -20,17 +20,15 @@
2020
* #L%
2121
*/
2222

23-
import com.fasterxml.jackson.core.JsonStreamContextAccessor;
23+
import com.fasterxml.jackson.core.json.JsonWriteContext;
2424

25-
import static com.fasterxml.jackson.core.JsonStreamContextAccessor.TYPE_ROOT;
25+
import static com.fasterxml.jackson.core.JsonStreamContext.TYPE_ROOT;
2626

2727
/**
2828
* Helper class to allow {@code com.fasterxml.jackson.core.json.JsonWriteContext} state access.
2929
*/
3030
public class JsonWriteContextAccessor {
3131

32-
private final JsonStreamContextAccessor streamCtxAccess = new JsonStreamContextAccessor();
33-
3432
public JsonWriteContext reset(JsonWriteContext ctx) {
3533

3634
if (ctx.getParent() == null) {
@@ -46,8 +44,8 @@ public JsonWriteContext reset(JsonWriteContext ctx) {
4644
return parent.reset(TYPE_ROOT);
4745
}
4846

49-
int getType(JsonWriteContext ctx) {
50-
return streamCtxAccess.getType(ctx);
47+
/* visible for testing */
48+
boolean inRoot(JsonWriteContext ctxAfterReset) {
49+
return ctxAfterReset.inRoot();
5150
}
52-
5351
}

log4j2-elasticsearch-core/src/main/java/org/appenders/log4j2/elasticsearch/ReusableUTF8JsonGenerator.java

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import com.fasterxml.jackson.core.JsonStreamContext;
2424
import com.fasterxml.jackson.core.ObjectCodec;
2525
import com.fasterxml.jackson.core.io.IOContext;
26-
import com.fasterxml.jackson.core.json.JsonWriteContextAccessor;
2726
import com.fasterxml.jackson.core.json.UTF8JsonGenerator;
2827

2928
import java.io.IOException;

log4j2-elasticsearch-core/src/main/java/org/appenders/log4j2/elasticsearch/SingleThreadJsonFactory.java

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import com.fasterxml.jackson.core.ObjectCodec;
2727
import com.fasterxml.jackson.core.io.CharacterEscapes;
2828
import com.fasterxml.jackson.core.io.IOContext;
29-
import com.fasterxml.jackson.core.json.JsonWriteContextAccessor;
3029
import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
3130

3231
import java.io.DataOutput;

log4j2-elasticsearch-core/src/test/java/com/fasterxml/jackson/core/json/ReusableUTF8JsonGeneratorTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.fasterxml.jackson.core.JsonGenerator;
2424
import com.fasterxml.jackson.core.util.BufferRecycler;
2525
import com.fasterxml.jackson.databind.ObjectMapper;
26+
import org.appenders.log4j2.elasticsearch.JsonWriteContextAccessor;
2627
import org.appenders.log4j2.elasticsearch.OutputStreamDelegate;
2728
import org.appenders.log4j2.elasticsearch.ReusableIOContext;
2829
import org.appenders.log4j2.elasticsearch.ReusableUTF8JsonGenerator;
+9-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.fasterxml.jackson.core.json;
1+
package org.appenders.log4j2.elasticsearch;
22

33
/*-
44
* #%L
@@ -20,12 +20,12 @@
2020
* #L%
2121
*/
2222

23+
import com.fasterxml.jackson.core.json.JsonWriteContext;
2324
import org.junit.Test;
2425

25-
import static com.fasterxml.jackson.core.JsonStreamContextAccessor.TYPE_ROOT;
26-
import static org.junit.Assert.assertEquals;
27-
import static org.junit.Assert.assertNotEquals;
26+
import static org.junit.Assert.assertFalse;
2827
import static org.junit.Assert.assertSame;
28+
import static org.junit.Assert.assertTrue;
2929

3030
public class JsonWriteContextAccessorTest {
3131

@@ -34,14 +34,14 @@ public void resetResetsCurrentContextImmediatelyIfContextHasNoParent() {
3434

3535
// given
3636
JsonWriteContextAccessor ctxAccess = new JsonWriteContextAccessor();
37-
JsonWriteContext context = new JsonWriteContext(TYPE_ROOT, null, null);
37+
JsonWriteContext context = JsonWriteContext.createRootContext(null);
3838

3939
// when
4040
JsonWriteContext ctxAfterReset = ctxAccess.reset(context);
4141

4242
// then
4343
assertSame(context, ctxAfterReset);
44-
assertEquals(ctxAccess.getType(ctxAfterReset), TYPE_ROOT);
44+
assertTrue(ctxAccess.inRoot(ctxAfterReset));
4545

4646
}
4747

@@ -50,21 +50,18 @@ public void resetResetsAndReturnsRootContextIfContextHasParent() {
5050

5151
// given
5252
JsonWriteContextAccessor ctxAccess = new JsonWriteContextAccessor();
53-
JsonWriteContext grandpaContext = new JsonWriteContext(TYPE_ROOT, null, null);
53+
JsonWriteContext grandpaContext = JsonWriteContext.createRootContext(null);
5454
JsonWriteContext parentContext = grandpaContext.createChildObjectContext();
5555
JsonWriteContext childContext = parentContext.createChildObjectContext();
5656

57-
int childContextType = ctxAccess.getType(childContext);
58-
59-
assertNotEquals(ctxAccess.getType(childContext), TYPE_ROOT);
57+
assertFalse(ctxAccess.inRoot(childContext));
6058

6159
// when
6260
JsonWriteContext ctxAfterReset = ctxAccess.reset(childContext);
6361

6462
// then
6563
assertSame(grandpaContext, ctxAfterReset);
66-
assertEquals(TYPE_ROOT, ctxAccess.getType(ctxAfterReset));
67-
assertEquals(childContextType, ctxAccess.getType(childContext));
64+
assertTrue(ctxAccess.inRoot(ctxAfterReset));
6865

6966
}
7067

0 commit comments

Comments
 (0)