public Job getJob(String jid) throws IOException { Class<? extends Job> klass = Job.class; Object result = call("get", jid); if (result == null) { result = call("recur.get", jid); if (result == null) { return null; } klass = RecurringJob.class; } String json = result.toString(); InjectableValues inject = new InjectableValues.Std().addValue("client", this); return JSON.parse(json, klass, inject); }
public List<Job> getJobs(String... jids) throws IOException { if (jids.length == 0) { return new ArrayList<Job>(); } Object result = call("multiget", jids); if ("{}".equals(result.toString())) { return new ArrayList<Job>(); } InjectableValues inject = new InjectableValues.Std().addValue("client", this); JavaType javaType = new ObjectMapper().getTypeFactory().constructCollectionType(ArrayList.class, Job.class); return JSON.parse(result.toString(), javaType, inject); }
public List<Job> peek(int count) throws IOException { Object result = client.call("peek", name, Integer.toString(count)); if ("{}".equals(result)) { return new ArrayList<Job>(); } InjectableValues injectables = new InjectableValues.Std().addValue("client", client); JavaType javaType = new ObjectMapper().getTypeFactory().constructCollectionType(ArrayList.class, Job.class); List<Job> jobs = JSON.parse(result.toString(), javaType, injectables); return jobs; }
public List<Job> pop(int count) throws IOException { Object result = client.call("pop", name, client.getWorkerName(), Integer.toString(count)); if ("{}".equals(result)) { return new ArrayList<Job>(); } InjectableValues injectables = new InjectableValues.Std().addValue("client", client); JavaType javaType = new ObjectMapper().getTypeFactory().constructCollectionType(ArrayList.class, Job.class); List<Job> jobs = JSON.parse(result.toString(), javaType, injectables); return jobs; }
@Test public void testParseGetResponse1() throws IOException { String json = Resources.toString(Resources.getResource(JSONTest.class, "getResponse1.json"), Charset.defaultCharset()); InjectableValues injectables = new InjectableValues.Std().addValue("client", EasyMock.createNiceMock(QlessClient.class)); Job job = JSON.parse(json, Job.class, injectables); Assert.assertEquals("77687e485b0442c6b043c52620bac347", job.jid); Assert.assertEquals(5, job.originalRetries); Assert.assertNotNull(job.data); Assert.assertEquals(true, job.data.isEmpty()); Assert.assertNotNull(job.failure); Assert.assertEquals(true, job.failure.isEmpty()); Assert.assertEquals(0, job.expiresAt); Assert.assertEquals(5, job.retriesLeft); //TODO:spawned_from_jid Assert.assertNotNull(job.dependencies); Assert.assertEquals(0, job.dependencies.size()); Assert.assertEquals("foo", job.klassName); Assert.assertEquals(false, job.tracked); Assert.assertNotNull(job.tags); Assert.assertEquals(0, job.tags.size()); Assert.assertEquals("Foo", job.queueName); Assert.assertEquals("waiting", job.state); Assert.assertNotNull(job.history); Assert.assertEquals(1, job.history.size()); Assert.assertNotNull(job.history.get(0).when()); Assert.assertEquals(1406824938L, job.history.get(0).when().longValue()); Assert.assertEquals("Foo", job.history.get(0).queueName()); Assert.assertEquals("put", job.history.get(0).what()); Assert.assertNotNull(job.dependents); Assert.assertEquals(0, job.dependents.size()); Assert.assertEquals(0, job.priority); Assert.assertEquals("", job.workerName); }
@Test public void testParsePopResponse1() throws IOException { String json = Resources.toString(Resources.getResource(JSONTest.class, "popResponse1.json"), Charset.defaultCharset()); InjectableValues injectables = new InjectableValues.Std().addValue("client", EasyMock.createNiceMock(QlessClient.class)); JavaType javaType = new ObjectMapper().getTypeFactory().constructCollectionType(ArrayList.class, Job.class); List<Job> jobs = JSON.parse(json, javaType, injectables); Assert.assertNotNull(jobs); Assert.assertEquals(1, jobs.size()); Assert.assertEquals("58ee8f40ce4e4e65b66332b915cddaaa", jobs.get(0).jid); Assert.assertEquals(1406831012, jobs.get(0).expiresAt); }
@Inject public GeoLabelObjectMapper(TransformationDescriptionResources resources) { super(); InjectableValues injectableValues = new InjectableValues.Std().addValue(TransformationDescriptionResources.class, resources); setInjectableValues(injectableValues); log.info("NEW {}", this); }
public StdDeserializationContext(DeserializationConfig paramDeserializationConfig, JsonParser paramJsonParser, DeserializerProvider paramDeserializerProvider, InjectableValues paramInjectableValues) { super(paramDeserializationConfig); this._parser = paramJsonParser; this._deserProvider = paramDeserializerProvider; this._injectableValues = paramInjectableValues; }
public static <T> T parse(String json, Class<T> klass) throws IOException { return parse(json, klass, new InjectableValues.Std()); }
public static <T> T parse(String json, JavaType javaType) throws IOException { return parse(json, javaType, new InjectableValues.Std()); }
public static <T> T parse(String json, Class<T> klass, InjectableValues injectables) throws IOException { ObjectMapper mapper = new ObjectMapper(); mapper.configure(Feature.FAIL_ON_UNKNOWN_PROPERTIES, false); return mapper.reader(klass).withInjectableValues(injectables).readValue(json); }
public static <T> T parse(String json, JavaType javaType, InjectableValues injectables) throws IOException { ObjectMapper mapper = new ObjectMapper(); mapper.configure(Feature.FAIL_ON_UNKNOWN_PROPERTIES, false); return mapper.reader(javaType).withInjectableValues(injectables).readValue(json); }