Advertisement
bakhridinova

Untitled

Oct 9th, 2023
713
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.83 KB | None | 0 0
  1. import com.fasterxml.jackson.annotation.JsonFormat;
  2. import com.fasterxml.jackson.annotation.JsonProperty;
  3. import lombok.Getter;
  4. import lombok.Setter;
  5.  
  6. import static com.fasterxml.jackson.annotation.JsonFormat.Feature.ACCEPT_CASE_INSENSITIVE_PROPERTIES;
  7.  
  8. @Getter
  9. @Setter
  10. @JsonFormat(with = ACCEPT_CASE_INSENSITIVE_PROPERTIES)
  11. public class ApplicationDefinition {
  12.     private Application application;
  13.  
  14.     @Getter
  15.     @Setter
  16.     @JsonFormat(with = ACCEPT_CASE_INSENSITIVE_PROPERTIES)
  17.     public static class Application {
  18.         @JsonProperty(required = true)
  19.         private String art;
  20.  
  21.         @JsonProperty(required = true)
  22.         private String team;
  23.     }
  24. }
  25.  
  26. import com.ebsco.platform.shared.gateway.request.executor.exception.MissingRepositoryOwnerException;
  27. import com.fasterxml.jackson.core.JsonProcessingException;
  28. import com.fasterxml.jackson.databind.DeserializationFeature;
  29. import com.fasterxml.jackson.databind.ObjectMapper;
  30. import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
  31. import lombok.RequiredArgsConstructor;
  32. import lombok.extern.slf4j.Slf4j;
  33. import org.springframework.stereotype.Service;
  34.  
  35. import javax.annotation.PostConstruct;
  36.  
  37. @Slf4j
  38. @Service
  39. @RequiredArgsConstructor
  40. public class GithubService {
  41.     ...
  42.     private final ObjectMapper yamlMapper = new ObjectMapper(new YAMLFactory());
  43.    
  44.     @PostConstruct
  45.     public void init() {
  46.         yamlMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
  47.     }  
  48.     ...
  49.        
  50.     private ... method(...) {
  51.         try (...) {
  52.         ...
  53.             ApplicationDefinition applicationDefinition = yamlMapper
  54.                 .readValue(getApplicationDefinitionFromResponse(response), ApplicationDefinition.class);
  55.         ...
  56.         } catch (JsonProcessingException e) {
  57.             throw new MissingRepositoryOwnerException(e.getMessage());
  58.         }
  59.     }
  60. }
  61.  
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement