Skip to content

Commit

Permalink
Repackaging of Jackson FasterXML package-private classes (#56)
Browse files Browse the repository at this point in the history
* Cleanup before module extraction
  • Loading branch information
rfoltyns committed Dec 9, 2020
1 parent 8b22a62 commit 63cf944
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 56 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.fasterxml.jackson.core.json;
package org.appenders.log4j2.elasticsearch;

/*-
* #%L
Expand All @@ -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) {
Expand All @@ -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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.fasterxml.jackson.core.json;
package org.appenders.log4j2.elasticsearch;

/*-
* #%L
Expand All @@ -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 {

Expand All @@ -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));

}

Expand All @@ -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));

}

Expand Down

0 comments on commit 63cf944

Please sign in to comment.