«JavaType» работает! Я пытался отменить сортировку (deserialize) List в json String в ArrayList java Objects и изо всех сил пытался найти решение с тех пор. Ниже приведен код, который, наконец, дал мне решение. Код:
JsonMarshallerUnmarshaller<T> {
T targetClass;
public ArrayList<T> unmarshal(String jsonString) {
ObjectMapper mapper = new ObjectMapper();
AnnotationIntrospector introspector = new JacksonAnnotationIntrospector();
mapper.getDeserializationConfig()
.withAnnotationIntrospector(introspector);
mapper.getSerializationConfig()
.withAnnotationIntrospector(introspector);
JavaType type = mapper.getTypeFactory().
constructCollectionType(
ArrayList.class,
targetclass.getClass());
try {
Class c1 = this.targetclass.getClass();
Class c2 = this.targetclass1.getClass();
ArrayList<T> temp = (ArrayList<T>)
mapper.readValue(jsonString, type);
return temp ;
} catch (JsonParseException e) {
e.printStackTrace();
} catch (JsonMappingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null ;
}
}
Предполагая, что строка с ошибкой действительно:
binary(i) = num2str(r(i));
Затем, при вызове функции с аргументом 25.10, до достижения этой строки имеем:
i=1
r=1.10000
num2str(r(i)) = '1.1'
Вот почему атрибуция
binary(i) = num2str(r(i));
Не работает. В Matlab двоичный код (1) представляет собой массив символов 1x1. Вы пытаетесь вписать в него массив символов 1x3 ('1.1').