@Override public AsyncFuture<Void> run(final ShellIO io, final TaskParameters base) throws Exception { final Parameters params = (Parameters) base; final String queryString = params.query.stream().collect(Collectors.joining(" ")); final ObjectMapper indent = mapper.copy(); indent.configure(SerializationFeature.INDENT_OUTPUT, true); final QueryOptions.Builder optionsBuilder = QueryOptions.builder().tracing(params.tracing); params.dataLimit.ifPresent(optionsBuilder::dataLimit); params.groupLimit.ifPresent(optionsBuilder::groupLimit); params.seriesLimit.ifPresent(optionsBuilder::seriesLimit); final QueryOptions options = optionsBuilder.build(); final Optional<QueryDateRange> range = Optional.of(new QueryDateRange.Relative(TimeUnit.DAYS, 1)); return query .useGroup(params.group) .query( query .newQueryFromString(queryString) .options(Optional.of(options)) .rangeIfAbsent(range) .build()) .directTransform( result -> { for (final RequestError e : result.getErrors()) { io.out().println(String.format("ERR: %s", e.toString())); } io.out().println(String.format("LIMITS: %s", result.getLimits().getLimits())); for (final ShardedResultGroup resultGroup : result.getGroups()) { final MetricCollection group = resultGroup.getMetrics(); io.out() .println( String.format( "%s: %s %s", group.getType(), resultGroup.getShard(), indent.writeValueAsString(resultGroup.getSeries()))); io.out().println(indent.writeValueAsString(group.getData())); io.out().flush(); } io.out().println("TRACE:"); result.getTrace().formatTrace(io.out()); io.out().flush(); return null; }); }
public void testAnnotationIntrospectorCopyin() { ObjectMapper m = new ObjectMapper(); m.setAnnotationIntrospector(new MyAnnotationIntrospector()); assertEquals( MyAnnotationIntrospector.class, m.getDeserializationConfig().getAnnotationIntrospector().getClass()); ObjectMapper m2 = m.copy(); assertEquals( MyAnnotationIntrospector.class, m2.getDeserializationConfig().getAnnotationIntrospector().getClass()); assertEquals( MyAnnotationIntrospector.class, m2.getSerializationConfig().getAnnotationIntrospector().getClass()); }
// [Issue#28]: ObjectMapper.copy() public void testCopy() throws Exception { ObjectMapper m = new ObjectMapper(); assertTrue(m.isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)); m.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); assertFalse(m.isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)); InjectableValues inj = new InjectableValues.Std(); m.setInjectableValues(inj); assertFalse(m.isEnabled(JsonParser.Feature.ALLOW_COMMENTS)); m.enable(JsonParser.Feature.ALLOW_COMMENTS); assertTrue(m.isEnabled(JsonParser.Feature.ALLOW_COMMENTS)); // // First: verify that handling of features is decoupled: ObjectMapper m2 = m.copy(); assertFalse(m2.isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)); m2.enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); assertTrue(m2.isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)); assertSame(inj, m2.getInjectableValues()); // but should NOT change the original assertFalse(m.isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)); // nor vice versa: assertFalse(m.isEnabled(DeserializationFeature.UNWRAP_ROOT_VALUE)); assertFalse(m2.isEnabled(DeserializationFeature.UNWRAP_ROOT_VALUE)); m.enable(DeserializationFeature.UNWRAP_ROOT_VALUE); assertTrue(m.isEnabled(DeserializationFeature.UNWRAP_ROOT_VALUE)); assertFalse(m2.isEnabled(DeserializationFeature.UNWRAP_ROOT_VALUE)); // // Also, underlying JsonFactory instances should be distinct assertNotSame(m.getFactory(), m2.getFactory()); // [Issue#122]: Need to ensure mix-ins are not shared assertEquals(0, m.getSerializationConfig().mixInCount()); assertEquals(0, m2.getSerializationConfig().mixInCount()); assertEquals(0, m.getDeserializationConfig().mixInCount()); assertEquals(0, m2.getDeserializationConfig().mixInCount()); m.addMixIn(String.class, Integer.class); assertEquals(1, m.getSerializationConfig().mixInCount()); assertEquals(0, m2.getSerializationConfig().mixInCount()); assertEquals(1, m.getDeserializationConfig().mixInCount()); assertEquals(0, m2.getDeserializationConfig().mixInCount()); // [Issue#913]: Ensure JsonFactory Features copied assertTrue(m2.isEnabled(JsonParser.Feature.ALLOW_COMMENTS)); }
public Stream<T> parse(InputStream is, CsvErrorSniffer context) { ObjectMapper mapper = objectMapper.copy(); formatter.initMixIn(mapper); ObjectReader reader = mapper.readerFor(formatter.getTargetClass()); CsvSchema schema = new CsvSchema(formatter); return parseToCsvLine(is) .map( line -> { line.getException() .ifPresent( e -> context.mark(new Location(line.getLineNumber(), OptionalInt.empty()))); Set<String> ignoreField = new HashSet<>(); while (true) { try { return reader.readValue(schema.toJson(line, ignoreField)); } catch (JsonMappingException e) { String path = buildPath(e.getPath()); ; Location location = new Location( line.getLineNumber(), OptionalInt.of(schema.getColumnNumber(path))); if (context.contains(location)) { throw new IllegalStateException("invalid row state: " + e.getLocation()); } context.mark(location); ignoreField.add(path); } catch (IOException e) { context.mark(new Location(line.getLineNumber(), OptionalInt.empty())); try { return formatter.getTargetClass().newInstance(); } catch (ReflectiveOperationException e2) { throw new ReflectiveOperationRuntimeException(e2); } } } }); }
public CsvParser(CsvFormatter<T> csvFormatter, ObjectMapper objectMapper) { this.formatter = csvFormatter; this.objectMapper = objectMapper.copy(); }