I have a Json array file and it has multiple data. As you can see in the data bellow you'll notice timeLastUpdate multiple times. When I compile in Java, the output i get is only the first timeLastUpdate in the JSON. I want all of the timeLastUpdate shown in Java. How do i do that?
example of data:
[
{
"mmsi": "253336000",
"status": "RESTRICTED_MANEUVERABILITY",
"courseOverGround": 7.9,
"timeLastUpdate": 1464545149000,
"
},
{
"mmsi": "253336000",
"timeLastUpdate": 1464545209000,
"destination": "ZEEBRUGGE",
},
]
Code Java :
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.DeserializationFeature;
import java.io.File;
import java.net.URL;
import java.io.IOException;
public class ShipMain {
public static void main(String[] args) throws JsonParseException, JsonMappingException, IOException {
File jsonFile2 = new File("shiphistory.json");
ShipData shiphistory = null;
ObjectMapper mapper = new ObjectMapper(); // can reuse, share globally
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
shiphistory = mapper.readValue(jsonFile2, ShipData.class);
System.out.println("______________ History_________");
System.out.println("Ship Name : " + shiphistory.getName());
System.out.println("Ship MMSI : " + shiphistory.getMmsi());
System.out.println("Ship Type : " + shiphistory.getShipType());
System.out.println("Ship Departure : " + shiphistory.getTimeLastUpdate());
}
}