Spring boot: Read json file and convert it to pojo[part2]

  Рет қаралды 801

cellon lush

cellon lush

Күн бұрын

Пікірлер: 3
@ukaszt5026
@ukaszt5026 2 жыл бұрын
Hey, How to import Item? i tried copy yours import, but it does not work and how to refecator this last line to universal method?
@cellonlush5583
@cellonlush5583 2 жыл бұрын
Hi, Item is just my pojo. It could be any Object.
@cellonlush5583
@cellonlush5583 2 жыл бұрын
package com.my.guitarstore.model; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonValue; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import org.springframework.util.ObjectUtils; import javax.persistence.*; import javax.validation.constraints.NotNull; import java.util.stream.Stream; @Entity(name = "items") @Data @ApiModel(value = "Item", description = "The item object that contains the details pertaining to an item") public class Item { public enum ItemState { NEW("New"), USED("Used"); public final String value; ItemState(String value) { this.value = value; } @JsonCreator public static ItemState convert(final String itemState) { ItemState inputItemState = Stream.of(ItemState.values()).filter(targetEnum -> targetEnum.value.equals(itemState)) .findFirst().orElse(null); if(ObjectUtils.isEmpty(inputItemState)) throw new IllegalArgumentException("Invalid value for ItemState"); return inputItemState; } @JsonValue public String getValue() {return value;} } @ApiModelProperty(name = "itemId", value = "Unique identifier for the item") @JsonInclude(JsonInclude.Include.NON_EMPTY) @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long itemId; @ApiModelProperty(name = "name", value = "Item name") @JsonInclude(JsonInclude.Include.NON_EMPTY) @NotNull private String name; @ApiModelProperty(name = "regularPrice", value = "regular price") @JsonInclude(JsonInclude.Include.NON_EMPTY) @NotNull private Double regularPrice; //columnDefinition = "boolean default false", @ApiModelProperty(name = "couponApplicable", value = "Indicate whether coupon is applicable or not on the item") @JsonInclude(JsonInclude.Include.NON_EMPTY) @Column( name = "couponApplicable") private Boolean couponApplicable; @ApiModelProperty(name = "sale discount", value = "Percentage of sale discount") @JsonInclude(JsonInclude.Include.NON_EMPTY) @Transient private Discount discount; @ApiModelProperty(name = "itemState", value = "Indicate whether the item is used or new", example = "New") @JsonInclude(JsonInclude.Include.NON_EMPTY) @NotNull @Column(name = "itemState") @Enumerated(EnumType.STRING) private ItemState itemState; @ApiModelProperty(name = "amount", value = "The number of Item", example = "1") @JsonInclude(JsonInclude.Include.NON_EMPTY) @NotNull private Integer amount; }
Spring boot: Read json file and convert it to pojo
8:16
cellon lush
Рет қаралды 7 М.
Two Sum - LeetCode - Java
5:32
cellon lush
Рет қаралды 39
Правильный подход к детям
00:18
Beatrise
Рет қаралды 11 МЛН
The evil clown plays a prank on the angel
00:39
超人夫妇
Рет қаралды 53 МЛН
push project to github repo in IntelliJ
2:40
cellon lush
Рет қаралды 244
Advent of Spring Boot   DAY16
8:37
Xavier Bouclet
Рет қаралды 17
IntelliJ new UI how to add toolbar backward/forward buttons
2:01
cellon lush
Рет қаралды 2,7 М.
mysql installation window
2:10
cellon lush
Рет қаралды 32
7. How to create a jenkins Job| Free style
15:37
QA Automation Classes
Рет қаралды 54
9 AI Tools You MUST Be Using in 2025.
17:53
Ishan Sharma
Рет қаралды 56 М.
controlled assessment
29:49
Bradley Watkins
Рет қаралды 4
fibonacci series in Java(Recursive)
3:01
cellon lush
Рет қаралды 28
Правильный подход к детям
00:18
Beatrise
Рет қаралды 11 МЛН