Eu cheguei a criar o código classe Controller:
@PostMapping("/report")
public ResponseEntity<Object> saveReport(@RequestBody @Valid List<ReportDTO> reportDTOList){
reportDTOList.forEach(reportDTO -> {
var report = new Report();
BeanUtils.copyProperties(teportDTO, new Report());
reportDTO = reportMapper.toDto(report);
reportService.save(reportDTO);
});
return ResponseEntity.status(HttpStatus.CREATED).body(reportDTOList);
}
Codigo da classe service para salvar:
public Report save(ReportDTO reportDTO) {
log.debug("Request to save Report : {}", reportDTO);
Report report = reportMapper.toEntity(reportDTO);
return this.reportRepository.save(report);
}
Quando executo o código tomo o 400
Bad Request: JSON parse error: Cannot deserialize value of type java.util.ArrayList<br.com.service.dto.ReportDTO> from Object value (token JsonToken.START_OBJECT); nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize value of type java.util.ArrayList<br.com.service.dto.ReportDTO> from Object value (token JsonToken.START_OBJECT)_ at [Source: (org.springframework.util.StreamUtils$NonClosingInputStream); line: 1, column: 1]
Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize value of type java.util.ArrayList<br.com.service.dto.ReportDTO> from Object value (token JsonToken.START_OBJECT); nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize value of type java.util.ArrayList<br.com.service.dto.ReportDTO> from Object value (token JsonToken.START_OBJECT) at [Source: (org.springframework.util.StreamUtils$NonClosingInputStream); line: 1, column: 1]]
O JsonToken é um Enum criado pelo próprio Jhipster e não me deixa alterar:
public enum JsonToken {
NOT_AVAILABLE((String)null, -1),
START_OBJECT("{", 1),
END_OBJECT("}", 2),
START_ARRAY("[", 3),
END_ARRAY("]", 4),
FIELD_NAME((String)null, 5),
VALUE_EMBEDDED_OBJECT((String)null, 12),
VALUE_STRING((String)null, 6),
VALUE_NUMBER_INT((String)null, 7),
VALUE_NUMBER_FLOAT((String)null, 8),
VALUE_TRUE("true", 9),
VALUE_FALSE("false", 10),
VALUE_NULL("null", 11);
final String _serialized;
final char[] _serializedChars;
final byte[] _serializedBytes;
final int _id;
final boolean _isStructStart;
final boolean _isStructEnd;
final boolean _isNumber;
final boolean _isBoolean;
final boolean _isScalar;
private JsonToken(String token, int id) {
if (token == null) {
this._serialized = null;
this._serializedChars = null;
this._serializedBytes = null;
} else {
this._serialized = token;
this._serializedChars = token.toCharArray();
int len = this._serializedChars.length;
this._serializedBytes = new byte[len];
for(int i = 0; i < len; ++i) {
this._serializedBytes[i] = (byte)this._serializedChars[i];
}
}
this._id = id;
this._isBoolean = id == 10 || id == 9;
this._isNumber = id == 7 || id == 8;
this._isStructStart = id == 1 || id == 3;
this._isStructEnd = id == 2 || id == 4;
this._isScalar = !this._isStructStart && !this._isStructEnd && id != 5 && id != -1;
}
public final int id() {
return this._id;
}
public final String asString() {
return this._serialized;
}
public final char[] asCharArray() {
return this._serializedChars;
}
public final byte[] asByteArray() {
return this._serializedBytes;
}
public final boolean isNumeric() {
return this._isNumber;
}
public final boolean isStructStart() {
return this._isStructStart;
}
public final boolean isStructEnd() {
return this._isStructEnd;
}
public final boolean isScalarValue() {
return this._isScalar;
}
public final boolean isBoolean() {
return this._isBoolean;
}