0

I assume a problen in class structure. But I do not see where. Here is a code. I'm gonna use only some values from JSON. If you need some other code part just let me know. Maily I think I get objest (user) wuth null values here:

User userDTOGetOne = userRequester.getUser
  (
    token,
    new HashMap<String, Object>() {{ put("Uuid", userResponseDTO.getUserUuid()); }}
   )
   .getBody()
   .as(User.class);

I suppose here is a problem .as(User.class) with class structure. I have compared them not once and I can not find a problem. Thank you in advance.

monty
  • 7,888
  • 16
  • 63
  • 100
  • Here is a link to the code https://drive.google.com/drive/folders/1OrHlWiiT4khiwqdT-t7QlYmOyT52NsTE?usp=sharing –  Jul 22 '21 at 09:51
  • Can you show the error that you got? – lucas-nguyen-17 Jul 22 '21 at 13:36
  • Problem is not solver to end, next heplped. Type to Integer change in : private Integer HighSchoolUuid; –  Jul 22 '21 at 13:37
  • And this variable also is modified to: private HashMap UserCustomFields; –  Jul 22 '21 at 13:38
  • I used handmade check to figure out where problems are. It was helpful: new ObjectMapper().writeValueAsString( new User() .set ....... –  Jul 22 '21 at 13:40
  • this set was the most interesring: .setUserCustomFields( new HashMap() {{ –  Jul 22 '21 at 13:42
  • put( "bb854ba1-8ef7-4cfb-9fe7-8c6d9a0551b2", new CustomFieldDTO() .setIsDefault(false) .setSerializedValue(SerializedValue1) ); –  Jul 22 '21 at 13:43
  • Please, edit your question to people know what your problem is, don't spam comment. Thanks – lucas-nguyen-17 Jul 22 '21 at 13:45
  • lucasnguyen17, the error in in the mistake.txt. The link to it you have in the first comment –  Jul 22 '21 at 13:46
  • also there is interesting thing. I've made seriliazation by hand - it works. But auto serialization does not work, I get nulls. The current code will be in NewTestCode.txt with the same link in a moment –  Jul 22 '21 at 13:50
  • Could you provide log request and response for this test, to make sure get you correct response before deserialization? – lucas-nguyen-17 Jul 22 '21 at 13:51

1 Answers1

0

Finally, I found out your problems.

1.@JsonRootName("User") in User class doesn't work, I have to create a separate UserDTo class.

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

@Data
public class UserDTO {
    @JsonProperty("User")
    private User user;
}

2.In class User

private HashMap<String, HashMap<String, CustomFieldDTO> > UserCustomFields;

should be

private Map<String, CustomFieldDTO> UserCustomFields;

3.In class CustomFieldDTO

private HashMap<String, CustomFieldVariableDTO> WebAdmin;
private HashMap<String, CustomFieldVariableDTO> Client;

should be

private CustomFieldVariableDTO WebAdmin;
private CustomFieldVariableDTO Client;

I make a simple test

UserDTO user = res.as(UserDTO.class);
System.out.println(user);

UserDTO(user=User(Uuid=b5ee1186-7355-4810-a422-c427c1ae420c, 
Username=golden_snich_testt, Email=golsnich4599@gmail.com, FirstName=Bob, 
LastName=Sigal, Birthdate=1995-01-07T00:00:00Z, Phone=+12698741258, 
Notes=null, Locked=false, PostPayLimit=10.0, HighSchoolUuid=null, 
IsVerifiedHighSchoolUser=false, UserCustomFields={9cebfaaa-ca66-4bbd-baa3- 
557b0645c293=CustomFieldDTO(FieldUuid=null, FieldType=String, 
FieldName=null, WebAdmin=CustomFieldVariableDTO(Status=0, 
AllowChangeStatus=false), Client=CustomFieldVariableDTO(Status=0, 
AllowChangeStatus=false), IsDefault=false, 
SerializedValue=Nickyfieldname213241), bb854ba1-8ef7-4cfb-9fe7- 
8c6d9a0551b2=CustomFieldDTO(FieldUuid=null, FieldType=String, 
FieldName=null, WebAdmin=CustomFieldVariableDTO(Status=0, 
AllowChangeStatus=false), Client=CustomFieldVariableDTO(Status=0, 
AllowChangeStatus=false), IsDefault=false, 
SerializedValue=Nickyfieldname2)}))
lucas-nguyen-17
  • 5,516
  • 2
  • 9
  • 20
  • Thank you. Is is workable. Some variable type changes I have figured out by myself. I checked only fields which I am in a need currently. And I have at the moment only one problematic field Notes. Firstly, could you be so pleased to explain why we needed additional DTO around User to make it workable, I thought is was okey. Secondly, about field Notes. I pass some value. Auto serialization returns me null. Serialization made by hand returns value. But I've noticed interesting thing in terminal. We get JSON structure of our user in terminal, this is our response, and we get there null in Notes –  Jul 23 '21 at 04:19
  • I mean that by default we get there null as response on our request. It is strange. I pass value. But I suppose it is suck logic mde by programmers –  Jul 23 '21 at 04:21
  • "User": { "Uuid": "9f12b830-263c-4488-ba8b-915954eea2a8", "Username": "golden_snich_testt", "Email": "golsnich4599@gmail.com", "FirstName": "Bob", "LastName": "Sigal", "CenterUuid": "4caf8e5a-e233-4206-8b73-e6e302b929ec", "Birthdate": "1995-01-07T00:00:00Z", "TimeRemaining": 0, "AccountStatus": "open", "StudentId": null, "Phone": "+12698741258", "LastSeen": null, "Deleted": false, "Notes": null This is a part of JSON from terminal after execution of my test –  Jul 23 '21 at 04:22
  • Because only one assert have not passed Failures: [ERROR] PostCreateUserApiTest.createUserSuccessfullyWithTestGroupAndDTOComparison:357 Multiple Failures (1 failure) Notes do not Match ==> expected: but was: –  Jul 23 '21 at 04:25
  • I added two png files - photos from the terminal about value of Notes field to the shared folder - the link is the same - you can find the link in the vety first comment –  Jul 23 '21 at 04:59
  • How have you figured out that annotation does not work? It was your thoughts, experience of solving such problems? Thank you –  Jul 23 '21 at 06:31
  • First, I sometimes use this for serialization not deserialization, it's strange for me. Second, when I turn it off, I see errors in other places (wrong types). – lucas-nguyen-17 Jul 23 '21 at 09:23
  • I have to admit that your code so verbose and ugly.(1) You should create smaller test and use compare object instead of compare each field (time-consuming). (2) Create object and fill data by using setters, you made very long Map in Map, it's so hard to follow, not good for maintainance. – lucas-nguyen-17 Jul 23 '21 at 09:50