Advertisement
Guest User

Untitled

a guest
Oct 8th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. package com.example.demo;
  2.  
  3. import com.fasterxml.jackson.annotation.JsonInclude;
  4. import org.springframework.stereotype.Service;
  5.  
  6. @Service
  7. public class DemoService {
  8.  
  9. public MyPojo getMyPojo() {
  10. MyPojo pojo = new MyPojo();
  11. pojo.setDateOfBirth("2010-08-12");
  12. pojo.setEmailAddress("veryyoungperson@gmail.com");
  13. pojo.setId(1234);
  14. pojo.setName("Dave");
  15. pojo.setParent(makeParent());
  16. return pojo;
  17. }
  18.  
  19. private MyPojo makeParent() {
  20. MyPojo pojo = new MyPojo();
  21. pojo.setName("Arnold");
  22. pojo.setId(3123);
  23. pojo.setDateOfBirth("1962-10-11");
  24. pojo.setEmailAddress("olderperson@gmail.com");
  25. pojo.setParent(makeSubParent());
  26. return pojo;
  27. }
  28.  
  29. private MyPojo makeSubParent() {
  30. MyPojo pojo = new MyPojo();
  31. pojo.setName("Javier");
  32. pojo.setId(4321);
  33. pojo.setDateOfBirth("1940-1-1");
  34. //pojo.setEmailAddress("other@gmail.com");
  35. return pojo;
  36. }
  37.  
  38.  
  39. public boolean isValid(MyPojo myPojo) {
  40. if (myPojo.getEmailAddress() == null && myPojo.getDateOfBirth().contains("ok")) {
  41. return false;
  42. }
  43. return myPojo.getEmailAddress().contains("c");
  44. }
  45. }
  46.  
  47. class MyPojo {
  48. private String name;
  49. private String dateOfBirth;
  50. private String emailAddress;
  51. private Integer id;
  52.  
  53. @JsonInclude(JsonInclude.Include.NON_ABSENT)
  54. private MyPojo parent;
  55.  
  56. public MyPojo getParent() {
  57. return parent;
  58. }
  59.  
  60. public void setParent(MyPojo parent) {
  61. this.parent = parent;
  62. }
  63.  
  64. public String getName() {
  65. return name;
  66. }
  67.  
  68. public void setName(String name) {
  69. this.name = name;
  70. }
  71.  
  72. public String getDateOfBirth() {
  73. return dateOfBirth;
  74. }
  75.  
  76. public void setDateOfBirth(String dateOfBirth) {
  77. this.dateOfBirth = dateOfBirth;
  78. }
  79.  
  80. public String getEmailAddress() {
  81. return emailAddress;
  82. }
  83.  
  84. public void setEmailAddress(String emailAddress) {
  85. this.emailAddress = emailAddress;
  86. }
  87.  
  88. public Integer getId() {
  89. return id;
  90. }
  91.  
  92. public void setId(Integer id) {
  93. this.id = id;
  94. }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement