| 1 | package pl.zankowski.iextrading4j.client.mapper; | |
| 2 | ||
| 3 | import com.fasterxml.jackson.annotation.JsonFormat; | |
| 4 | import com.fasterxml.jackson.core.JsonParser; | |
| 5 | import com.fasterxml.jackson.databind.DeserializationContext; | |
| 6 | import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer; | |
| 7 | ||
| 8 | import java.io.IOException; | |
| 9 | import java.time.Instant; | |
| 10 | import java.time.LocalDate; | |
| 11 | import java.time.LocalDateTime; | |
| 12 | import java.time.ZoneId; | |
| 13 | import java.time.format.DateTimeFormatter; | |
| 14 | ||
| 15 | class HackyLocalDateDeserializer extends LocalDateDeserializer { | |
| 16 | ||
| 17 | private static final long serialVersionUID = -3767123317457549736L; | |
| 18 | ||
| 19 | private static final DateTimeFormatter DEFAULT_FORMATTER = DateTimeFormatter.ISO_LOCAL_DATE; | |
| 20 | ||
| 21 | HackyLocalDateDeserializer() { | |
| 22 | super(DEFAULT_FORMATTER); | |
| 23 | } | |
| 24 | ||
| 25 | HackyLocalDateDeserializer(DateTimeFormatter dtf) { | |
| 26 | super(dtf); | |
| 27 | } | |
| 28 | ||
| 29 | protected HackyLocalDateDeserializer(LocalDateDeserializer base, Boolean leniency) { | |
| 30 | super(base, leniency); | |
| 31 | } | |
| 32 | ||
| 33 | protected HackyLocalDateDeserializer(LocalDateDeserializer base, JsonFormat.Shape shape) { | |
| 34 | super(base, shape); | |
| 35 | } | |
| 36 | ||
| 37 | @Override | |
| 38 | protected LocalDateDeserializer withDateFormat(DateTimeFormatter dtf) { | |
| 39 |
1
1. withDateFormat : replaced return value with null for pl/zankowski/iextrading4j/client/mapper/HackyLocalDateDeserializer::withDateFormat → NO_COVERAGE |
return new HackyLocalDateDeserializer(dtf); |
| 40 | } | |
| 41 | ||
| 42 | @Override | |
| 43 | protected LocalDateDeserializer withLeniency(Boolean leniency) { | |
| 44 |
1
1. withLeniency : replaced return value with null for pl/zankowski/iextrading4j/client/mapper/HackyLocalDateDeserializer::withLeniency → NO_COVERAGE |
return new HackyLocalDateDeserializer(this, leniency); |
| 45 | } | |
| 46 | ||
| 47 | @Override | |
| 48 | protected LocalDateDeserializer withShape(JsonFormat.Shape shape) { | |
| 49 |
1
1. withShape : replaced return value with null for pl/zankowski/iextrading4j/client/mapper/HackyLocalDateDeserializer::withShape → NO_COVERAGE |
return new HackyLocalDateDeserializer(this, shape); |
| 50 | } | |
| 51 | ||
| 52 | @Override | |
| 53 | public LocalDate deserialize(final JsonParser parser, final DeserializationContext context) throws IOException { | |
| 54 | final String val = parser.getValueAsString(); | |
| 55 | ||
| 56 | // #HACK In Daily List they return "0" if data is not available | |
| 57 |
3
1. deserialize : negated conditional → KILLED 2. deserialize : negated conditional → KILLED 3. deserialize : negated conditional → KILLED |
if (val == null || val.equals("0") || val.equals("0000-00-00")) { |
| 58 | return null; | |
| 59 | } | |
| 60 | ||
| 61 |
2
1. deserialize : changed conditional boundary → KILLED 2. deserialize : negated conditional → KILLED |
if (val.length() > 10) { |
| 62 | LocalDateTime dateTime = | |
| 63 | LocalDateTime.ofInstant(Instant.ofEpochMilli(Long.parseLong(val)), ZoneId.systemDefault()); | |
| 64 |
1
1. deserialize : replaced return value with null for pl/zankowski/iextrading4j/client/mapper/HackyLocalDateDeserializer::deserialize → NO_COVERAGE |
return dateTime.toLocalDate(); |
| 65 | } | |
| 66 | ||
| 67 |
1
1. deserialize : replaced return value with null for pl/zankowski/iextrading4j/client/mapper/HackyLocalDateDeserializer::deserialize → KILLED |
return super.deserialize(parser, context); |
| 68 | } | |
| 69 | } | |
Mutations | ||
| 39 |
1.1 |
|
| 44 |
1.1 |
|
| 49 |
1.1 |
|
| 57 |
1.1 2.2 3.3 |
|
| 61 |
1.1 2.2 |
|
| 64 |
1.1 |
|
| 67 |
1.1 |