Skip to content
This repository has been archived by the owner on Feb 16, 2022. It is now read-only.

Commit

Permalink
Merge pull request #21 from StaticDefault/master
Browse files Browse the repository at this point in the history
Added classloader parameter.
  • Loading branch information
StaticDefaultTester2 authored Nov 7, 2019
2 parents 4a975e6 + 272481e commit dfdf493
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
11 changes: 9 additions & 2 deletions src/main/java/com/realtimetech/kson/KsonContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,18 @@ private static enum ValueMode {

private HashMap<String, Class<?>> cachedClasses;

private ClassLoader classLoader;

public KsonContext() {
this(10, 100);
}

public KsonContext(int stackSize, int stringBufferSize) {
this(KsonContext.class.getClassLoader(), stackSize, stringBufferSize);
}

public KsonContext(ClassLoader classLoader, int stackSize, int stringBufferSize) {
this.classLoader = classLoader;
this.working = false;
this.valueStack = new FastStack<Object>(stackSize);
this.modeStack = new FastStack<ValueMode>(stackSize);
Expand Down Expand Up @@ -218,7 +225,7 @@ public UUID deserialize(KsonContext ksonContext, Class<?> object, Object value)

private Class<?> getClassByName(String name) throws ClassNotFoundException {
if (!this.cachedClasses.containsKey(name)) {
this.cachedClasses.put(name, Class.forName(name));
this.cachedClasses.put(name, classLoader.loadClass(name));
}

return this.cachedClasses.get(name);
Expand Down
17 changes: 15 additions & 2 deletions src/main/java/com/realtimetech/kson/builder/KsonBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class KsonBuilder {

private HashMap<Class<?>, Transformer<?>> registeredTransformers;

private ClassLoader classLoader;
private int stackSize;
private int stringBufferSize;

Expand All @@ -28,12 +29,24 @@ public KsonBuilder registerTransformer(Class<?> clazz, Transformer<?> preTransfo
return this;
}

public ClassLoader getClassLoader() {
return classLoader;
}

public KsonBuilder setClassLoader(ClassLoader classLoader) {
this.classLoader = classLoader;

return this;
}

public boolean isUseCustomTag() {
return useCustomTag;
}

public void setUseCustomTag(boolean useCustomTag) {
public KsonBuilder setUseCustomTag(boolean useCustomTag) {
this.useCustomTag = useCustomTag;

return this;
}

public int getStackSize() {
Expand All @@ -57,7 +70,7 @@ public KsonBuilder setStringBufferSize(int stringBufferSize) {
}

public KsonContext build() {
KsonContext ksonContext = new KsonContext(this.stackSize, this.stringBufferSize);
KsonContext ksonContext = new KsonContext(this.classLoader, this.stackSize, this.stringBufferSize);

ksonContext.setUseCustomTag(this.useCustomTag);

Expand Down

0 comments on commit dfdf493

Please sign in to comment.