4
4
import com .fasterxml .jackson .annotation .JsonIgnoreProperties ;
5
5
import com .fasterxml .jackson .annotation .JsonInclude ;
6
6
import com .fasterxml .jackson .annotation .JsonProperty ;
7
- import com .fasterxml .jackson .core .JsonParser ;
8
- import com .fasterxml .jackson .core .JsonProcessingException ;
9
7
import com .fasterxml .jackson .databind .JavaType ;
10
8
import com .fasterxml .jackson .databind .ObjectMapper ;
11
9
import com .fasterxml .jackson .databind .annotation .JsonDeserialize ;
22
20
@ JsonIgnoreProperties (ignoreUnknown = true )
23
21
public class Predicate {
24
22
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 ;
34
32
35
33
@ 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 ,
38
36
@ 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 ;
50
48
}
51
49
52
50
public static <T > T fromLine (String line ) {
@@ -59,27 +57,25 @@ public static <T> List<T> listFromLine(String line) {
59
57
60
58
protected static <T > T parse (String line , JavaType type ) {
61
59
T result = null ;
62
- if (! StringUtils . isBlank ( line ) && isValidJSON ( line )) {
63
- try {
60
+ try {
61
+ if (! StringUtils . isBlank ( line ) && isValidJSON ( line )) {
64
62
result = new ObjectMapper ().readValue (line , type );
65
- } catch (JsonProcessingException ignored ) {
66
63
67
64
}
65
+ } catch (IOException e ) {
66
+ e .printStackTrace ();
68
67
}
69
68
return result ;
70
69
}
71
70
72
71
private static boolean isValidJSON (final String json ) {
73
- boolean valid = false ;
74
72
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 ;
81
78
}
82
- return valid ;
83
79
}
84
80
85
81
}
0 commit comments