setup ffsaf server
This commit is contained in:
28
src/main/java/fr/titionfire/ffsaf/utils/JsonConsumer.java
Normal file
28
src/main/java/fr/titionfire/ffsaf/utils/JsonConsumer.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package fr.titionfire.ffsaf.utils;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.TreeNode;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static fr.titionfire.ffsaf.net2.Client_Thread.MAPPER;
|
||||
|
||||
public class JsonConsumer<T> implements Consumer<T> {
|
||||
|
||||
private final Class<T> clazz;
|
||||
private final Consumer<T> consumer;
|
||||
|
||||
public JsonConsumer(Class<T> clazz, Consumer<T> consumer){
|
||||
this.clazz = clazz;
|
||||
this.consumer = consumer;
|
||||
}
|
||||
|
||||
public void castAndAccept (TreeNode message) throws JsonProcessingException {
|
||||
this.accept(MAPPER.treeToValue(message, clazz));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(T t) {
|
||||
consumer.accept(t);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user