@Test @SuppressWarnings({ "rawtypes", "unchecked" }) public void annotationStyleJackson1ProducesJackson1Annotations() throws ClassNotFoundException, SecurityException, NoSuchMethodException { Class generatedType = schemaRule.generateAndCompile("/schema/properties/primitiveProperties.json", "com.example", config("annotationStyle", "jackson1")) .loadClass("com.example.PrimitiveProperties"); assertThat(schemaRule.getGenerateDir(), not(containsText("com.fasterxml.jackson"))); assertThat(schemaRule.getGenerateDir(), containsText("org.codehaus.jackson")); Method getter = generatedType.getMethod("getA"); assertThat(generatedType.getAnnotation(org.codehaus.jackson.annotate.JsonPropertyOrder.class), is(notNullValue())); assertThat(generatedType.getAnnotation(org.codehaus.jackson.map.annotate.JsonSerialize.class), is(notNullValue())); assertThat(getter.getAnnotation(org.codehaus.jackson.annotate.JsonProperty.class), is(notNullValue())); }
@Test public void shouldCreateByteArrayFieldWithAnyEncoding() throws SecurityException, NoSuchFieldException { Field field = classWithMediaProperties.getDeclaredField("anyBinaryEncoding"); JsonSerialize serAnnotation = field.getAnnotation(JsonSerialize.class); JsonDeserialize deserAnnotation = field.getAnnotation(JsonDeserialize.class); assertThat("any binary encoding field has type byte[]", field.getType(), equalToType(BYTE_ARRAY)); assertThat("any binary encoding has a serializer", serAnnotation, notNullValue()); assertThat("any binary encoding has a deserializer", deserAnnotation, notNullValue()); }
@Override public void propertyField(JFieldVar field, JDefinedClass clazz, String propertyName, JsonNode propertyNode) { if( isQuotedPrintableProperty(propertyNode) ) { field.annotate(JsonSerialize.class).param(USING, QuotedPrintableSerializer.class); field.annotate(JsonInclude.class).param("value", JsonInclude.Include.NON_NULL); field.annotate(JsonDeserialize.class).param(USING, QuotedPrintableDeserializer.class); } }
@Override @JsonSerialize(using = Jackson2HalModule.HalResourcesSerializer.class) @JsonDeserialize(using = Jackson2HalModule.HalResourcesDeserializer.class) public PagedIncidents getIncidentsPaged(int pagenum,int pagesize) { LOG.info("Performing get {} web service", applicationProperties.getIncidentApiUrl() +"/incidents"); final String restUri = applicationProperties.getIncidentApiUrl() +"/incidents?page="+pagenum+"&size="+pagesize; ResponseEntity<PagedResources<IncidentBean>> response = restTemplate.exchange(restUri, HttpMethod.GET, null, new ParameterizedTypeReference<PagedResources<IncidentBean>>() {}); // LOG.info("Total Incidents {}", response.getBody().size()); PagedResources<IncidentBean> beanResources = response.getBody(); PagedIncidents incidents = new PagedIncidents(beanResources,pagenum); return incidents; }
@Test @SuppressWarnings({ "rawtypes", "unchecked" }) public void annotationStyleNoneProducesNoAnnotations() throws ClassNotFoundException, SecurityException, NoSuchMethodException { ClassLoader resultsClassLoader = schemaRule.generateAndCompile("/schema/properties/primitiveProperties.json", "com.example", config("annotationStyle", "none")); Class generatedType = resultsClassLoader.loadClass("com.example.PrimitiveProperties"); Method getter = generatedType.getMethod("getA"); assertThat(generatedType.getAnnotation(JsonPropertyOrder.class), is(nullValue())); assertThat(generatedType.getAnnotation(JsonSerialize.class), is(nullValue())); assertThat(getter.getAnnotation(JsonProperty.class), is(nullValue())); }
@AdditionalJacksonAnnotation("some_long") @JsonProperty("some_long_string") @JsonSerialize(using=ToStringSerializer.class) Long getSomeLong();
@JsonProperty("int_value_property") @JsonSerialize(converter = IntValueOverrideConverter.StringSerializer.class) @JsonDeserialize(converter = IntValueOverrideConverter.StringDeserializer.class) abstract IntValueClass getIntValue();
@JsonSerialize(contentAs = String.class) public Set<String> getIgnored() { return ignored; }
@JsonDeserialize(converter = Time.Nano2Instant.class) @JsonSerialize(converter = Time.Instant2Nano.class) Instant importTime();
@JsonDeserialize(converter = Time.Nano2Instant.class) @JsonSerialize(converter = Time.Instant2Nano.class) Instant lastUsedTime();
@JsonDeserialize(converter = Time.Nano2Instant.class) @JsonSerialize(converter = Time.Instant2Nano.class) Instant createdAt();
@JsonDeserialize(converter = Time.Nano2Instant.class) @JsonSerialize(converter = Time.Instant2Nano.class) Instant startedAt();
@JsonSerialize(using = ToStringSerializer.class) public ZoneId getTimeZone() { return timeZone; }
@JsonSerialize(using = ToStringSerializer.class) public Locale getLocale() { return locale; }
@JsonSerialize(using = ToStringSerializer.class) public OffsetDateTime getOrigin() { return origin; }
@JsonSerialize(using = ToStringSerializer.class) public ZonedDateTime getTimestamp() { return timestamp; }
@JsonProperty("session") @JsonSerialize(using = SimpleSessionJsonSerializer.class) public SimpleSession session() { return session; }
@JsonProperty @JsonSerialize(contentUsing = ServerPortSerializer.class) List<ServerPort> ports() { return ports; }
@JsonProperty @JsonSerialize(converter = OptionalConverter.class) Optional<Integer> numWorkers() { return Optional.ofNullable(numWorkers); }
@JsonProperty @JsonSerialize(converter = OptionalConverter.class) Optional<Integer> maxNumConnections() { return Optional.ofNullable(maxNumConnections); }
@JsonProperty @JsonSerialize(converter = OptionalConverter.class) Optional<Long> requestTimeoutMillis() { return Optional.ofNullable(requestTimeoutMillis); }
@JsonProperty @JsonSerialize(converter = OptionalConverter.class) Optional<Long> idleTimeoutMillis() { return Optional.ofNullable(idleTimeoutMillis); }
@JsonProperty @JsonSerialize(converter = OptionalConverter.class) Optional<Integer> maxFrameLength() { return Optional.ofNullable(maxFrameLength); }
@JsonProperty @JsonSerialize(converter = OptionalConverter.class) Optional<GracefulShutdownTimeout> gracefulShutdownTimeout() { return Optional.ofNullable(gracefulShutdownTimeout); }
@Value.Redacted @JsonSerialize(using=SensitiveByteArraySerializer.class) public abstract byte[] password();
@Nullable @Value.Redacted @JsonSerialize(using=SensitiveByteArraySerializer.class) @JsonDeserialize(using=SensitiveByteArrayDeserializer.class) public abstract byte[] token();
@Value.Redacted @JsonProperty(access = WRITE_ONLY) @JsonSerialize(using=SensitiveByteArraySerializer.class) @JsonDeserialize(using=SensitiveByteArrayDeserializer.class) public abstract byte[] accessToken();
@Value.Redacted @JsonSerialize(using=SensitiveByteArraySerializer.class) @JsonDeserialize(using=SensitiveByteArrayDeserializer.class) public abstract byte[] refreshToken();
@JsonSerialize(using = DistributionTargetSerializer.class) @JsonDeserialize(using = DistributionTargetDeserializer.class) abstract List<Workbasket> getDistributionTargets();
@JsonSerialize(using=DPIDSerializer.class) public DatapathId getSwitchDPID() { return dpid; }
/** * @return the posted */ @JsonSerialize(using = CustomDateToLongSerializer.class) public Date getPosted() { return posted; }
/** * @return the posted */ @JsonProperty(JP_POSTED) @JsonSerialize(using = CustomDateToStringSerializer.class) public Date getPosted() { return posted; }
@JsonSerialize(using = LocalDateSerializer.class) @JsonDeserialize(using = LocalDateDeserializer.class) @JsonFormat(shape = JsonFormat.Shape.STRING) public LocalDate getStartDate() { return startDate; }
@JsonSerialize(using = LocalDateSerializer.class) @JsonDeserialize(using = LocalDateDeserializer.class) @JsonFormat(shape = JsonFormat.Shape.STRING) public LocalDate getEndDate() { return endDate; }
@JsonSerialize(using = ScoreJacksonJsonSerializer.class) @JsonDeserialize(using = HardSoftScoreJacksonJsonDeserializer.class) public HardSoftScore getScore() { return score; }
@JsonSerialize(using = LocalDateTimeSerializer.class) @JsonDeserialize(using = LocalDateTimeDeserializer.class) @JsonFormat(shape = JsonFormat.Shape.STRING) public LocalDateTime getStartDateTime() { return startDateTime; }