1 package org.oxerr.okcoin.rest.dto.valuereader;
2
3 import java.io.IOException;
4 import java.io.InputStream;
5
6 import javax.annotation.Nullable;
7
8 import org.apache.http.entity.ContentType;
9 import org.oxerr.okcoin.rest.dto.Result;
10 import org.oxerr.okcoin.rest.service.web.LoginRequiredException;
11
12 import com.fasterxml.jackson.databind.JsonMappingException;
13 import com.fasterxml.jackson.databind.ObjectMapper;
14
15 public class ResultValueReader implements ValueReader<Result> {
16
17 private static final ResultValueReader INSTANCE = new ResultValueReader();
18
19 private JsonValueReader<Result> jsonValueReader;
20
21 public static ResultValueReader getInstance() {
22 return INSTANCE;
23 }
24
25 public ResultValueReader() {
26 ObjectMapper objectMapper = new ObjectMapper();
27 jsonValueReader = new JsonValueReader<>(objectMapper, Result.class);
28 }
29
30
31
32
33 @Override
34 public Result read(InputStream inputStream,
35 @Nullable ContentType contentType) throws IOException {
36 try {
37 return jsonValueReader.read(inputStream, contentType);
38 } catch (JsonMappingException e) {
39 throw new LoginRequiredException(e.getMessage(), e);
40 }
41 }
42
43 }