How To Append Additional Data Via The ToObject Method?
In this answer, and the user has appended something to the toObject method here:
PostModel changedModel = documentChange.getDocument().toObject(PostModel.class).withDocId(docID);
Where and how do I define the withDocId
so that I can pass the docId? Is it in the POJO class?
My POJO class has this method:
public void withDocId(String docId) {
this.docId = docId;
}
Answer
The following line of code:
documentChange.getDocument().toObject(PostModel.class)
Returns an object of type PostModel
. When calling .withDocId(docID)
on that object, it means that withDocId
method is a method within that class.
Is it in the POJO class?
Yes it is.
Edit:
how do I define it in the POJO class?
You can define a method in your POJO class in the same way you define the setters and getters. So it might be something line this:
public void withDocId(String docID) {
//Your logic
}
Edit2:
In order to make this line of code compile:
PostModel changedModel = documentChange.getDocument().toObject(PostModel.class).withDocId(docID);
The .withDocId(docID)
should return an object of type PostModel
. So most likely the return type of your method should be PostModel
. The above method was only an example. If you want to return a String, then you should change:
String docID = documentChange.getDocument().toObject(PostModel.class).withDocId(docID);
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM