Ошибка получения,
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class com.app.server.data.MyUser and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: java.util.ArrayList[0])
at com.fasterxml.jackson.databind.exc.InvalidDefinitionException.from(InvalidDefinitionException.java:77) ~[jackson-databind-2.10.2.jar:2.10.2]
at com.fasterxml.jackson.databind.SerializerProvider.reportBadDefinition(SerializerProvider.java:1191) ~[jackson-databind-2.10.2.jar:2.10.2]
at com.fasterxml.jackson.databind.DatabindContext.reportBadDefinition(DatabindContext.java:404) ~[jackson-databind-2.10.2.jar:2.10.2]
at com.fasterxml.jackson.databind.ser.impl.UnknownSerializer.failForEmpty(UnknownSerializer.java:71) ~[jackson-databind-2.10.2.jar:2.10.2]
at com.fasterxml.jackson.databind.ser.impl.UnknownSerializer.serialize(UnknownSerializer.java:33) ~[jackson-databind-2.10.2.jar:2.10.2]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.java:145) ~[jackson-databind-2.10.2.jar:2.10.2]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.java:107) ~[jackson-databind-2.10.2.jar:2.10.2]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.java:25) ~[jackson-databind-2.10.2.jar:2.10.2]
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider._serialize(DefaultSerializerProvider.java:480) ~[jackson-databind-2.10.2.jar:2.10.2]
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:400) ~[jackson-databind-2.10.2.jar:2.10.2]
at com.fasterxml.jackson.databind.ObjectWriter$Prefetch.serialize(ObjectWriter.java:1429) ~[jackson-databind-2.10.2.jar:2.10.2]
at com.fasterxml.jackson.databind.ObjectWriter.writeValue(ObjectWriter.java:921) ~[jackson-databind-2.10.2.jar:2.10.2]
При вызове функции ниже из загрузочного контроллера Spring,
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
@Repository
public class JdbcUserRepository implements UserRepository {
@Autowired
private JdbcTemplate jdbcTemplate;
@Override
public List<MyUser> findAll() {
return jdbcTemplate.query( "select * from users", (rs, rowNum) ->
new MyUser(
rs.getLong("user_id"),
rs.getString("user_nid"),
rs.getString("user_name"),
rs.getString("user_duid")
)
);
}
}
Модель:
public class MyUser {
Long userId;
String userNid;
String userName;
String userDuid;
public MyUser(Long userId, String userNid, String userName, String userDuid) {
super();
this.userId = userId;
this.userNid = userNid;
this.userName = userName;
this.userDuid = userDuid;
}
}
браузеры, выдающие ошибку,
There was an unexpected error (type=Internal Server Error, status=500).
Type definition error: [simple type, class com.app.server.data.MyUser]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class com.app.server.data.MyUser and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: java.util.ArrayList[0])
Как я могу решить это?