Код: Выделить всё
[
{
"id": 25651,
"title": "German Tour: Parliament Quarter & Reichstag glass dome",
"price": 14,
"currency": "$",
"rating": 4.8,
"specialOffer": false,
"supplierId": 1
},
{
"id": 6960,
"title": "Skip the Line: Pergamon Museum Berlin Tickets",
"price": 21,
"currency": "$",
"rating": 4.8,
"specialOffer": false,
"supplierId": 2
}
]
Код: Выделить всё
import com.fasterxml.jackson.annotation.*;
import lombok.*;
@Data
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class Activity {
private Long id;
private String title;
private int price;
private String currency;
private double rating;
private boolean specialOffer;
}
Код: Выделить всё
@GetMapping("/filter")
public void filter(@RequestParam(name = "search", required = false, defaultValue = "NONE") String searchString, Model model) {
try {
model.addAttribute("searchString", searchString);
//create ObjectMapper instance
ObjectMapper objectMapper = new ObjectMapper();
//read JSON file and convert to a list of activities
var fileInputStream = new ClassPathResource("static/activities.json").getInputStream();
var activities = objectMapper.readValue(fileInputStream, new TypeReference() {
});
var filteredData = searchFilter(title, activities);
System.out.println("filteredData = " + filteredData);
model.addAttribute("activities", activities);
} catch (Exception e) {
e.printStackTrace();
}
}
Спасибо за помощь
Подробнее здесь: https://stackoverflow.com/questions/790 ... ing-spring