I have a Spring-Boot
with Mongo application where I am trying to persist a list of object.
I have a method which parses some json data and creates a list of objects. I then call the save
method of MongoRepository
to save it all in a go.
The Repository code looks like:
public interface TicketRepository extends MongoRepository<Ticket, String> {
}
And Ticket
object POJO is:
@Document
public class Ticket {
@Id
private String id;
private String topic;
private String type;
private long brand;
private long group;
private String priority;
private String status;
private String created_date;
private String created_time;
private String channel;
public Ticket() {
}
//.........getters and setters....
}
Now, some of the fields for some objects would be null as well because I do not set any values for them.
And finally, this is how I save them:
@RestController
public class TicketController {
@Autowired
TicketRepository ticketRepository;
@GetMapping("/tickets")
public void saveTicketData() {
List<Ticket> tickets = null;
try {
tickets = getTicketObjectList(ticketJson);
ticketRepository.save(tickets);
} catch (DuplicateKeyException e) {
System.out.println("duplicate found!");
} catch (Exception e) {
e.printStackTrace();
}
}
}
This throws NullPointerExcetion
on save method call without any further stacktrace.
What could be the cause?