Tomasm21
Tomasm21
JCHJava Community | Help. Code. Learn.
Created by circle on 11/16/2024 in #java-help
ResponseEntity incorrectly maps values
I reported it to Springdoc issues on github.
49 replies
JCHJava Community | Help. Code. Learn.
Created by circle on 11/16/2024 in #java-help
ResponseEntity incorrectly maps values
The problem is in front-end. For unknown reason Swagger shows variant ids wrong. But in response body numbers are correct.
49 replies
JCHJava Community | Help. Code. Learn.
Created by circle on 11/16/2024 in #java-help
ResponseEntity incorrectly maps values
When I debugged like you then in service method ProductDto is with correct variant ids for both loading Variants eagerly or lazily.
49 replies
JCHJava Community | Help. Code. Learn.
Created by circle on 11/16/2024 in #java-help
ResponseEntity incorrectly maps values
I don't really know. Just also heard that beans with LAZY would be loaded when specifically requesting it. But I used it because chatgpt said that Hibernare might serialise Variants in products badly and might copy its previous object with older id when transaction is loaded lazily. So I switched to eager. But I don't think this is the solution.Just more strict rule for Hibernate to load all dependant entities at the same transaction.
49 replies
JCHJava Community | Help. Code. Learn.
Created by circle on 11/16/2024 in #java-help
ResponseEntity incorrectly maps values
Yea you can escape the problem with to string and choose what to show. But better to map to dtos.
49 replies
JCHJava Community | Help. Code. Learn.
Created by circle on 11/16/2024 in #java-help
ResponseEntity incorrectly maps values
So don't serialise sheer entities, but dtos.
49 replies
JCHJava Community | Help. Code. Learn.
Created by circle on 11/16/2024 in #java-help
ResponseEntity incorrectly maps values
Without those annotations if you would return entities instead of Dto represtations of it then you would get infinite references in entities serialisation to json. You would get infinite loop that would lead to stack overflow abd exception.
49 replies
JCHJava Community | Help. Code. Learn.
Created by circle on 11/16/2024 in #java-help
ResponseEntity incorrectly maps values
Now you will
49 replies
JCHJava Community | Help. Code. Learn.
Created by circle on 11/16/2024 in #java-help
ResponseEntity incorrectly maps values
So, ResponseEntity maps values correctly. Just Swagger from Springdoc shows it incorrectly in UI even though response body in developer tools network tab is correct.
49 replies
JCHJava Community | Help. Code. Learn.
Created by circle on 11/16/2024 in #java-help
ResponseEntity incorrectly maps values
Maybe bug.
49 replies
JCHJava Community | Help. Code. Learn.
Created by circle on 11/16/2024 in #java-help
ResponseEntity incorrectly maps values
I don't know what magic happens at http://localhost:8081/swagger-ui/index.html in their Response body output. But that's strange.
49 replies
JCHJava Community | Help. Code. Learn.
Created by circle on 11/16/2024 in #java-help
ResponseEntity incorrectly maps values
And also fetch it eagerly.
49 replies
JCHJava Community | Help. Code. Learn.
Created by circle on 11/16/2024 in #java-help
ResponseEntity incorrectly maps values
And I removed @JsonBackReference from Variant.product and @JsonManagedReference from Product.variants since you use dtos when get that data:
@Entity
@SQLRestriction("deleted = false")
@Getter
@Setter
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class Product extends Auditables {

//...

@OneToMany(mappedBy = "product", fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
//@JsonManagedReference
private Set<Variant> variants = new HashSet<>();

@OneToMany(mappedBy = "product", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
@JsonManagedReference
private Set<ProductImage> images = new HashSet<>();
//...
}
@Entity
@SQLRestriction("deleted = false")
@Getter
@Setter
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class Product extends Auditables {

//...

@OneToMany(mappedBy = "product", fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
//@JsonManagedReference
private Set<Variant> variants = new HashSet<>();

@OneToMany(mappedBy = "product", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
@JsonManagedReference
private Set<ProductImage> images = new HashSet<>();
//...
}
and:
@Entity
@Getter
@Setter
@EqualsAndHashCode(callSuper = true, exclude = "product")
//@ToString(callSuper = true, exclude = "product")
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Variant extends Auditables {

//...

@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "product_id", nullable = false)
//@JsonBackReference
private Product product;

//...
}
@Entity
@Getter
@Setter
@EqualsAndHashCode(callSuper = true, exclude = "product")
//@ToString(callSuper = true, exclude = "product")
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Variant extends Auditables {

//...

@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "product_id", nullable = false)
//@JsonBackReference
private Product product;

//...
}
49 replies
JCHJava Community | Help. Code. Learn.
Created by circle on 11/16/2024 in #java-help
ResponseEntity incorrectly maps values
No description
49 replies
JCHJava Community | Help. Code. Learn.
Created by circle on 11/16/2024 in #java-help
ResponseEntity incorrectly maps values
No description
49 replies
JCHJava Community | Help. Code. Learn.
Created by circle on 11/16/2024 in #java-help
ResponseEntity incorrectly maps values
and compare response body:
49 replies
JCHJava Community | Help. Code. Learn.
Created by circle on 11/16/2024 in #java-help
ResponseEntity incorrectly maps values
open Developer tools network tab
49 replies
JCHJava Community | Help. Code. Learn.
Created by circle on 11/16/2024 in #java-help
ResponseEntity incorrectly maps values
The problem is in Swagger itself
49 replies
JCHJava Community | Help. Code. Learn.
Created by circle on 11/16/2024 in #java-help
ResponseEntity incorrectly maps values
Hi
49 replies
JCHJava Community | Help. Code. Learn.
Created by circle on 11/9/2024 in #java-help
Populate Spring Data JPA before each @Test
Making friend request to be able to send direct message.
45 replies