44import com .fasterxml .jackson .annotation .JsonIgnoreProperties ;
55import com .fasterxml .jackson .annotation .JsonInclude ;
66import com .fasterxml .jackson .annotation .JsonProperty ;
7- import com .fasterxml .jackson .core .JsonParser ;
8- import com .fasterxml .jackson .core .JsonProcessingException ;
97import com .fasterxml .jackson .databind .JavaType ;
108import com .fasterxml .jackson .databind .ObjectMapper ;
119import com .fasterxml .jackson .databind .annotation .JsonDeserialize ;
2220@ JsonIgnoreProperties (ignoreUnknown = true )
2321public class Predicate {
2422
25- String ID ;
26- String SimilarityID ;
27- String ProjectID ;
28- String State ;
29- String Severity ;
30- String Comment ;
31- String CreatedBy ;
32- String CreatedAt ;
33- String UpdatedAt ;
23+ String id ;
24+ String similarityId ;
25+ String projectId ;
26+ String state ;
27+ String severity ;
28+ String comment ;
29+ String createdBy ;
30+ String createdAt ;
31+ String updatedAt ;
3432
3533 @ JsonCreator
36- public Predicate (@ JsonProperty ("ID" ) String id , @ JsonProperty ("SimilarityID" ) String similarityID ,
37- @ JsonProperty ("ProjectID" ) String projectID , @ JsonProperty ("State" ) String state ,
34+ public Predicate (@ JsonProperty ("ID" ) String id , @ JsonProperty ("SimilarityID" ) String similarityId ,
35+ @ JsonProperty ("ProjectID" ) String projectId , @ JsonProperty ("State" ) String state ,
3836 @ JsonProperty ("Severity" ) String severity , @ JsonProperty ("Comment" ) String comment ,
39- @ JsonProperty ("CreatedBy" ) String createdBy , @ JsonProperty ("CreatedAt" ) String CreatedAt ,
40- @ JsonProperty ("UpdatedAt" ) String UpdatedAt ) {
41- this .ID = id ;
42- this .SimilarityID = similarityID ;
43- this .ProjectID = projectID ;
44- this .State = state ;
45- this .Severity = severity ;
46- this .Comment = comment ;
47- this .CreatedBy = createdBy ;
48- this .CreatedAt = CreatedAt ;
49- this .UpdatedAt = UpdatedAt ;
37+ @ JsonProperty ("CreatedBy" ) String createdBy , @ JsonProperty ("CreatedAt" ) String createdAt ,
38+ @ JsonProperty ("UpdatedAt" ) String updatedAt ) {
39+ this .id = id ;
40+ this .similarityId = similarityId ;
41+ this .projectId = projectId ;
42+ this .state = state ;
43+ this .severity = severity ;
44+ this .comment = comment ;
45+ this .createdBy = createdBy ;
46+ this .createdAt = createdAt ;
47+ this .updatedAt = updatedAt ;
5048 }
5149
5250 public static <T > T fromLine (String line ) {
@@ -59,27 +57,25 @@ public static <T> List<T> listFromLine(String line) {
5957
6058 protected static <T > T parse (String line , JavaType type ) {
6159 T result = null ;
62- if (! StringUtils . isBlank ( line ) && isValidJSON ( line )) {
63- try {
60+ try {
61+ if (! StringUtils . isBlank ( line ) && isValidJSON ( line )) {
6462 result = new ObjectMapper ().readValue (line , type );
65- } catch (JsonProcessingException ignored ) {
6663
6764 }
65+ } catch (IOException e ) {
66+ e .printStackTrace ();
6867 }
6968 return result ;
7069 }
7170
7271 private static boolean isValidJSON (final String json ) {
73- boolean valid = false ;
7472 try {
75- final JsonParser parser = new ObjectMapper ().createParser (json );
76- //noinspection StatementWithEmptyBody
77- while (parser .nextToken () != null ) {
78- }
79- valid = true ;
80- } catch (IOException ignored ) {
73+ final ObjectMapper mapper = new ObjectMapper ();
74+ mapper .readTree (json );
75+ return true ;
76+ } catch (IOException e ) {
77+ return false ;
8178 }
82- return valid ;
8379 }
8480
8581}
0 commit comments