I have a jersey project glassfish 2.18and am trying to read the JSON file routes.txtin this folder with the main sources using Jackson 2.x. How can I get an InputStream of a text document file to get data from it?
I appreciate any help
The code:
FileReader fileReader = new FileReader("src/main/sources/routes.txt");
ObjectMapper mapper = new ObjectMapper();
Root readValue = mapper.readValue(fileReader, Root.class);
JSON simple:
[{
"route": 1,
"info": {
"stops": [{
"arrival_time": {"mon-fri": ["04:24","05:10","05:40"],
"sat": ["05:34","05:55","06:15"],
"son": ["07:00","08:00","05:40"]
},
"stops_name": "Tension Way"
}],
"direction": "Surrey Quays"
}
}]
Root class:
package org.busTracker.serverSide.json;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Generated;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
@JsonInclude(JsonInclude.Include.NON_NULL)
@Generated("org.jsonschema2pojo")
@JsonPropertyOrder({
"route",
"info"
})
public class Root {
@JsonProperty("route")
private Integer route;
@JsonProperty("info")
private Info info;
@JsonIgnore
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
@JsonProperty("route")
public Integer getRoute() {
return route;
}
@JsonProperty("route")
public void setRoute(Integer route) {
this.route = route;
}
@JsonProperty("info")
public Info getInfo() {
return info;
}
@JsonProperty("info")
public void setInfo(Info info) {
this.info = info;
}
@JsonAnyGetter
public Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
}
@JsonAnySetter
public void setAdditionalProperty(String name, Object value) {
this.additionalProperties.put(name, value);
}
}
source
share