I want to post ArrayList, but return null valueSpring Security OAuth2 SSO with Custom provider + logoutJakson polymorphic Enum caseError returned when trying to call my local webservice using springboot(Spring, Thymeleaf) How to request to controller 'POST' with list of model inside a model?MockMvc post junit test returning 415 when ResponseBody have collectionspringboot-mongodb CRUD applicationSpring boot security cannot log in after invalid credentialso.s.web.servlet.PageNotFound No mapping for GETSpring Controller gives me 404 status error@Value in Springboot returns null
Cubic programming and beyond?
Where is the USB2 OTG port on the RPi 4 Model B located?
Bishop game - python
How can one write good dialogue in a story without sounding wooden?
Why would guns not work in the dungeon?
I quit, and boss offered me 3 month "grace period" where I could still come back
Redirect https to fqdn
affect vs effect
Where or how can I find what interfaces an out of the box Apex class implements?
Why did my rum cake turn black?
Machine learning and operations research projects
Why do players in the past play much longer tournaments than today's top players?
Are there any intersection of Theory A and Theory B?
How might the United Kingdom become a republic?
What is temperature on a quantum level
Correct use of ergeben?
Creating custom objects with custom properties using generics
What is the difference between logical consistency and logical entailment in deductive logic?
(async () => )(); what is this?
Does Google Maps take into account hills/inclines for route times?
Is `curl something | sudo bash -` a reasonably safe installation method?
Why isn't there research to build a standard lunar, or Martian mobility platform?
Supporting developers who insist on using their pet language
Professor falsely accusing me of cheating in a class he does not teach, two months after end of the class. What precautions should I take?
I want to post ArrayList, but return null value
Spring Security OAuth2 SSO with Custom provider + logoutJakson polymorphic Enum caseError returned when trying to call my local webservice using springboot(Spring, Thymeleaf) How to request to controller 'POST' with list of model inside a model?MockMvc post junit test returning 415 when ResponseBody have collectionspringboot-mongodb CRUD applicationSpring boot security cannot log in after invalid credentialso.s.web.servlet.PageNotFound No mapping for GETSpring Controller gives me 404 status error@Value in Springboot returns null
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
POSTMAN :
"childDTO":[
"age":"80",
"gender":"kavi",
"occupation":"main",
"type":"mainlife"
,
"age":"80",
"gender":"kavi",
"occupation":"main",
"type":"mainlife"
]
Controller.....
@PostMapping("/child")
public List<CustomerDTO> childDTO(@RequestBody CustomerDTO cus)
return calculationService.childDTO(cus.getAge(),cus.getGender(),cus.getOccupation(),cus.getType());
Service......
public List<CustomerDTO> childDTO(String age, String gender, String occupation, String type);
Service Impl......
@Override
public List<CustomerDTO> childDTO(String age, String gender, String occupation, String type)
List<CustomerDTO> typeChild = new ArrayList<>();
if (type==children)
for (CustomerDTO customer1 : typeChild)
customer1.setAge(age);
customer1.setGender(gender);
customer1.setOccupation(occupation);
customer1.setType(type);
customer1.setBenifits(benifitDTO(beni.getRiders(), beni.getSumAssuarance()));
System.out.println("list:-"+customer1);
typeChild.add(customer1);
System.out.println("list:-"+typeChild);
return typeChild;
spring-boot
add a comment |
POSTMAN :
"childDTO":[
"age":"80",
"gender":"kavi",
"occupation":"main",
"type":"mainlife"
,
"age":"80",
"gender":"kavi",
"occupation":"main",
"type":"mainlife"
]
Controller.....
@PostMapping("/child")
public List<CustomerDTO> childDTO(@RequestBody CustomerDTO cus)
return calculationService.childDTO(cus.getAge(),cus.getGender(),cus.getOccupation(),cus.getType());
Service......
public List<CustomerDTO> childDTO(String age, String gender, String occupation, String type);
Service Impl......
@Override
public List<CustomerDTO> childDTO(String age, String gender, String occupation, String type)
List<CustomerDTO> typeChild = new ArrayList<>();
if (type==children)
for (CustomerDTO customer1 : typeChild)
customer1.setAge(age);
customer1.setGender(gender);
customer1.setOccupation(occupation);
customer1.setType(type);
customer1.setBenifits(benifitDTO(beni.getRiders(), beni.getSumAssuarance()));
System.out.println("list:-"+customer1);
typeChild.add(customer1);
System.out.println("list:-"+typeChild);
return typeChild;
spring-boot
Can you please post code ofCustomerDTO
? and What value children will have!
– user3145373 ツ
Mar 26 at 5:19
private String age; private String gender; private String occupation; private String type; private BenifitsDTO benifits;
– kaveeth sri
Mar 26 at 5:33
So I think you post request will never be received as You're passing array data and in@RequestBody
you're trying to receive data in single object !
– user3145373 ツ
Mar 26 at 5:36
controller :-CustomerDTO [age=null, gender=null, occupation=null, type=null, benifits=null]
– kaveeth sri
Mar 26 at 5:39
post request data not assign in controller
– kaveeth sri
Mar 26 at 5:40
add a comment |
POSTMAN :
"childDTO":[
"age":"80",
"gender":"kavi",
"occupation":"main",
"type":"mainlife"
,
"age":"80",
"gender":"kavi",
"occupation":"main",
"type":"mainlife"
]
Controller.....
@PostMapping("/child")
public List<CustomerDTO> childDTO(@RequestBody CustomerDTO cus)
return calculationService.childDTO(cus.getAge(),cus.getGender(),cus.getOccupation(),cus.getType());
Service......
public List<CustomerDTO> childDTO(String age, String gender, String occupation, String type);
Service Impl......
@Override
public List<CustomerDTO> childDTO(String age, String gender, String occupation, String type)
List<CustomerDTO> typeChild = new ArrayList<>();
if (type==children)
for (CustomerDTO customer1 : typeChild)
customer1.setAge(age);
customer1.setGender(gender);
customer1.setOccupation(occupation);
customer1.setType(type);
customer1.setBenifits(benifitDTO(beni.getRiders(), beni.getSumAssuarance()));
System.out.println("list:-"+customer1);
typeChild.add(customer1);
System.out.println("list:-"+typeChild);
return typeChild;
spring-boot
POSTMAN :
"childDTO":[
"age":"80",
"gender":"kavi",
"occupation":"main",
"type":"mainlife"
,
"age":"80",
"gender":"kavi",
"occupation":"main",
"type":"mainlife"
]
Controller.....
@PostMapping("/child")
public List<CustomerDTO> childDTO(@RequestBody CustomerDTO cus)
return calculationService.childDTO(cus.getAge(),cus.getGender(),cus.getOccupation(),cus.getType());
Service......
public List<CustomerDTO> childDTO(String age, String gender, String occupation, String type);
Service Impl......
@Override
public List<CustomerDTO> childDTO(String age, String gender, String occupation, String type)
List<CustomerDTO> typeChild = new ArrayList<>();
if (type==children)
for (CustomerDTO customer1 : typeChild)
customer1.setAge(age);
customer1.setGender(gender);
customer1.setOccupation(occupation);
customer1.setType(type);
customer1.setBenifits(benifitDTO(beni.getRiders(), beni.getSumAssuarance()));
System.out.println("list:-"+customer1);
typeChild.add(customer1);
System.out.println("list:-"+typeChild);
return typeChild;
spring-boot
spring-boot
edited Mar 26 at 5:14
georges van
2,4632 gold badges25 silver badges40 bronze badges
2,4632 gold badges25 silver badges40 bronze badges
asked Mar 26 at 4:57
kaveeth srikaveeth sri
43 bronze badges
43 bronze badges
Can you please post code ofCustomerDTO
? and What value children will have!
– user3145373 ツ
Mar 26 at 5:19
private String age; private String gender; private String occupation; private String type; private BenifitsDTO benifits;
– kaveeth sri
Mar 26 at 5:33
So I think you post request will never be received as You're passing array data and in@RequestBody
you're trying to receive data in single object !
– user3145373 ツ
Mar 26 at 5:36
controller :-CustomerDTO [age=null, gender=null, occupation=null, type=null, benifits=null]
– kaveeth sri
Mar 26 at 5:39
post request data not assign in controller
– kaveeth sri
Mar 26 at 5:40
add a comment |
Can you please post code ofCustomerDTO
? and What value children will have!
– user3145373 ツ
Mar 26 at 5:19
private String age; private String gender; private String occupation; private String type; private BenifitsDTO benifits;
– kaveeth sri
Mar 26 at 5:33
So I think you post request will never be received as You're passing array data and in@RequestBody
you're trying to receive data in single object !
– user3145373 ツ
Mar 26 at 5:36
controller :-CustomerDTO [age=null, gender=null, occupation=null, type=null, benifits=null]
– kaveeth sri
Mar 26 at 5:39
post request data not assign in controller
– kaveeth sri
Mar 26 at 5:40
Can you please post code of
CustomerDTO
? and What value children will have!– user3145373 ツ
Mar 26 at 5:19
Can you please post code of
CustomerDTO
? and What value children will have!– user3145373 ツ
Mar 26 at 5:19
private String age; private String gender; private String occupation; private String type; private BenifitsDTO benifits;
– kaveeth sri
Mar 26 at 5:33
private String age; private String gender; private String occupation; private String type; private BenifitsDTO benifits;
– kaveeth sri
Mar 26 at 5:33
So I think you post request will never be received as You're passing array data and in
@RequestBody
you're trying to receive data in single object !– user3145373 ツ
Mar 26 at 5:36
So I think you post request will never be received as You're passing array data and in
@RequestBody
you're trying to receive data in single object !– user3145373 ツ
Mar 26 at 5:36
controller :-CustomerDTO [age=null, gender=null, occupation=null, type=null, benifits=null]
– kaveeth sri
Mar 26 at 5:39
controller :-CustomerDTO [age=null, gender=null, occupation=null, type=null, benifits=null]
– kaveeth sri
Mar 26 at 5:39
post request data not assign in controller
– kaveeth sri
Mar 26 at 5:40
post request data not assign in controller
– kaveeth sri
Mar 26 at 5:40
add a comment |
2 Answers
2
active
oldest
votes
You did not post what variable children
is, probably some class field, but you cannot compare Java Strings with ==
. Java Strings must be compared with .equals
:
...
if (type.equals(children)) {
...
Use a debugger next time, to see what's happening in your code.
add a comment |
Your request and controller RequestBody structure do not match.
You need to use List.
@PostMapping("/child")
public List<CustomerDTO> childDTO(@RequestBody List<CustomerDTO> cusList) // here list needs to be used
if(cusList != null && !cusList.isEmpty())
CustomerDTO cus = cusList.get(0); // it will get first element from the list, if you want to process all the elements then you need to iterate the list
return calculationService.childDTO(cus.getAge(),cus.getGender(),cus.getOccupation(),cus.getType());
Now other logic will be as it or you may change it as per your requirement.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55350100%2fi-want-to-post-arraylist-but-return-null-value%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You did not post what variable children
is, probably some class field, but you cannot compare Java Strings with ==
. Java Strings must be compared with .equals
:
...
if (type.equals(children)) {
...
Use a debugger next time, to see what's happening in your code.
add a comment |
You did not post what variable children
is, probably some class field, but you cannot compare Java Strings with ==
. Java Strings must be compared with .equals
:
...
if (type.equals(children)) {
...
Use a debugger next time, to see what's happening in your code.
add a comment |
You did not post what variable children
is, probably some class field, but you cannot compare Java Strings with ==
. Java Strings must be compared with .equals
:
...
if (type.equals(children)) {
...
Use a debugger next time, to see what's happening in your code.
You did not post what variable children
is, probably some class field, but you cannot compare Java Strings with ==
. Java Strings must be compared with .equals
:
...
if (type.equals(children)) {
...
Use a debugger next time, to see what's happening in your code.
answered Mar 26 at 5:14
StrelokStrelok
40k6 gold badges80 silver badges103 bronze badges
40k6 gold badges80 silver badges103 bronze badges
add a comment |
add a comment |
Your request and controller RequestBody structure do not match.
You need to use List.
@PostMapping("/child")
public List<CustomerDTO> childDTO(@RequestBody List<CustomerDTO> cusList) // here list needs to be used
if(cusList != null && !cusList.isEmpty())
CustomerDTO cus = cusList.get(0); // it will get first element from the list, if you want to process all the elements then you need to iterate the list
return calculationService.childDTO(cus.getAge(),cus.getGender(),cus.getOccupation(),cus.getType());
Now other logic will be as it or you may change it as per your requirement.
add a comment |
Your request and controller RequestBody structure do not match.
You need to use List.
@PostMapping("/child")
public List<CustomerDTO> childDTO(@RequestBody List<CustomerDTO> cusList) // here list needs to be used
if(cusList != null && !cusList.isEmpty())
CustomerDTO cus = cusList.get(0); // it will get first element from the list, if you want to process all the elements then you need to iterate the list
return calculationService.childDTO(cus.getAge(),cus.getGender(),cus.getOccupation(),cus.getType());
Now other logic will be as it or you may change it as per your requirement.
add a comment |
Your request and controller RequestBody structure do not match.
You need to use List.
@PostMapping("/child")
public List<CustomerDTO> childDTO(@RequestBody List<CustomerDTO> cusList) // here list needs to be used
if(cusList != null && !cusList.isEmpty())
CustomerDTO cus = cusList.get(0); // it will get first element from the list, if you want to process all the elements then you need to iterate the list
return calculationService.childDTO(cus.getAge(),cus.getGender(),cus.getOccupation(),cus.getType());
Now other logic will be as it or you may change it as per your requirement.
Your request and controller RequestBody structure do not match.
You need to use List.
@PostMapping("/child")
public List<CustomerDTO> childDTO(@RequestBody List<CustomerDTO> cusList) // here list needs to be used
if(cusList != null && !cusList.isEmpty())
CustomerDTO cus = cusList.get(0); // it will get first element from the list, if you want to process all the elements then you need to iterate the list
return calculationService.childDTO(cus.getAge(),cus.getGender(),cus.getOccupation(),cus.getType());
Now other logic will be as it or you may change it as per your requirement.
answered Mar 26 at 5:46
user3145373 ツuser3145373 ツ
5,0535 gold badges29 silver badges49 bronze badges
5,0535 gold badges29 silver badges49 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55350100%2fi-want-to-post-arraylist-but-return-null-value%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Can you please post code of
CustomerDTO
? and What value children will have!– user3145373 ツ
Mar 26 at 5:19
private String age; private String gender; private String occupation; private String type; private BenifitsDTO benifits;
– kaveeth sri
Mar 26 at 5:33
So I think you post request will never be received as You're passing array data and in
@RequestBody
you're trying to receive data in single object !– user3145373 ツ
Mar 26 at 5:36
controller :-CustomerDTO [age=null, gender=null, occupation=null, type=null, benifits=null]
– kaveeth sri
Mar 26 at 5:39
post request data not assign in controller
– kaveeth sri
Mar 26 at 5:40