public static class WrapperList implements List<Byte>
{
// delegate to methods of a wrapped ArrayList
}
WrapperList list = new WrapperList();
list.add((byte) 10);
ObjectMapper mapper = new ObjectMapper();
TypeFactory typeFactory = mapper.getTypeFactory();
JavaType type = typeFactory.constructType(list.getClass());
String canonicalTypeName = type.toCanonical();
typeFactory.constructFromCanonical(canonicalTypeName);Exception
in thread "main" java.lang.IllegalArgumentException: Can not create
TypeBindings for class org.camunda.bpm.Main$WrapperList with 1 type
parameter: class expects 0
at com.fasterxml.jackson.databind.type.TypeBindings.create(TypeBindings.java:125)
at com.fasterxml.jackson.databind.type.TypeBindings.create(TypeBindings.java:95)
at com.fasterxml.jackson.databind.type.TypeBindings.create(TypeBindings.java:86)
at com.fasterxml.jackson.databind.type.TypeParser.parseType(TypeParser.java:54)
at com.fasterxml.jackson.databind.type.TypeParser.parse(TypeParser.java:33)
at com.fasterxml.jackson.databind.type.TypeFactory.constructFromCanonical(TypeFactory.java:544)
at com.example.Main.main(Main.java:42)package com.example;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.type.TypeFactory;
public class Main {
public static void main(String[] args) throws IOException {
WrapperList list = new WrapperList();
list.add((byte) 10);
ObjectMapper mapper = new ObjectMapper();
TypeFactory typeFactory = mapper.getTypeFactory();
JavaType type = typeFactory.constructType(list.getClass());
System.out.println(type.toCanonical());
JavaType reconstructedType = typeFactory.constructFromCanonical(type.toCanonical());
}
public static class WrapperList implements List<Byte>
{
protected List<Byte> innerList = new ArrayList<Byte>();
public int size() {
return innerList.size();
}
public boolean isEmpty() {
return innerList.isEmpty();
}
public boolean contains(Object o) {
return innerList.contains(o);
}
public Iterator<Byte> iterator() {
return innerList.iterator();
}
public Object[] toArray() {
return innerList.toArray();
}
public <T> T[] toArray(T[] a) {
return innerList.toArray(a);
}
public boolean add(Byte e) {
return innerList.add(e);
}
public boolean remove(Object o) {
return innerList.remove(o);
}
public boolean containsAll(Collection<?> c) {
return innerList.containsAll(c);
}
public boolean addAll(Collection<? extends Byte> c) {
return innerList.addAll(c);
}
public boolean addAll(int index, Collection<? extends Byte> c) {
return innerList.addAll(index, c);
}
public boolean removeAll(Collection<?> c) {
return innerList.removeAll(c);
}
public boolean retainAll(Collection<?> c) {
return innerList.retainAll(c);
}
public void clear() {
innerList.clear();
}
public boolean equals(Object o) {
return innerList.equals(o);
}
public int hashCode() {
return innerList.hashCode();
}
public Byte get(int index) {
return innerList.get(index);
}
public Byte set(int index, Byte element) {
return innerList.set(index, element);
}
public void add(int index, Byte element) {
innerList.add(index, element);
}
public Byte remove(int index) {
return innerList.remove(index);
}
public int indexOf(Object o) {
return innerList.indexOf(o);
}
public int lastIndexOf(Object o) {
return innerList.lastIndexOf(o);
}
public ListIterator<Byte> listIterator() {
return innerList.listIterator();
}
public ListIterator<Byte> listIterator(int index) {
return innerList.listIterator(index);
}
public List<Byte> subList(int fromIndex, int toIndex) {
return innerList.subList(fromIndex, toIndex);
}
}
}
List<?> someList = ..;
String typeName;
if (!someList.isEmpty()) {
Object firstElement = list.get(0);
typeName = typeFactory.constructCollectionType(someList.getClass(), firstElement);
}
else
{
typeName = typeFactory.constructType(someList.getClass()); // or could simply use Class#getName
}