Java Code Examples for com.fasterxml.jackson.databind.annotation.JsonDeserialize

The following are top voted examples for showing how to use com.fasterxml.jackson.databind.annotation.JsonDeserialize. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: GitHub   File: Jackson2Annotator.java   View source code 6 votes vote down vote up
@Override
public void propertyField(JFieldVar field, JDefinedClass clazz, String propertyName, JsonNode propertyNode) {
    field.annotate(JsonProperty.class).param("value", propertyName);
    if (field.type().erasure().equals(field.type().owner().ref(Set.class))) {
        field.annotate(JsonDeserialize.class).param("as", LinkedHashSet.class);
    }

    if (propertyNode.has("javaJsonView")) {
        field.annotate(JsonView.class).param(
                "value", field.type().owner().ref(propertyNode.get("javaJsonView").asText()));
    }

    if (propertyNode.has("description")) {
        field.annotate(JsonPropertyDescription.class).param("value", propertyNode.get("description").asText());
    }
}
 
Example 2
Project: centraldogma   File: PublicKeyMirrorCredential.java   View source code 6 votes vote down vote up
@JsonCreator
public PublicKeyMirrorCredential(@JsonProperty("hostnamePatterns")
                                 @JsonDeserialize(contentAs = Pattern.class)
                                 Iterable<Pattern> hostnamePatterns,
                                 @JsonProperty("username") String username,
                                 @JsonProperty("publicKey") String publicKey,
                                 @JsonProperty("privateKey") String privateKey,
                                 @JsonProperty("passphrase") String passphrase) {

    super(hostnamePatterns);

    this.username = requireNonEmpty(username, "username");

    requireNonEmpty(publicKey, "publicKey");
    requireNonEmpty(privateKey, "privateKey");
    this.publicKey = requireNonEmpty(publicKey, "publicKey").getBytes(StandardCharsets.UTF_8);
    this.privateKey = requireNonEmpty(privateKey, "privateKey").getBytes(StandardCharsets.UTF_8);

    this.passphrase = decodeBase64OrUtf8(passphrase, "passphrase");
}
 
Example 3
Project: centraldogma   File: DefaultMetaRepository.java   View source code 6 votes vote down vote up
@JsonCreator
MultipleMirrorConfig(
        @JsonProperty("enabled") Boolean enabled,
        @JsonProperty("defaultSchedule") String defaultSchedule,
        @JsonProperty(value = "defaultDirection", required = true) MirrorDirection defaultDirection,
        @JsonProperty("defaultLocalPath") String defaultLocalPath,
        @JsonProperty(value = "includes", required = true)
        @JsonDeserialize(contentAs = MirrorInclude.class)
        Iterable<MirrorInclude> includes,
        @JsonProperty("excludes")
        @JsonDeserialize(contentAs = Pattern.class)
        Iterable<Pattern> excludes) {

    super(firstNonNull(enabled, true));
    this.defaultSchedule = cronParser.parse(firstNonNull(defaultSchedule, DEFAULT_SCHEDULE));
    this.defaultDirection = requireNonNull(defaultDirection, "defaultDirection");
    this.defaultLocalPath = firstNonNull(defaultLocalPath, "/");
    this.includes = ImmutableList.copyOf(requireNonNullElements(includes, "includes"));
    if (excludes != null) {
        this.excludes = ImmutableList.copyOf(requireNonNullElements(excludes, "excludes"));
    } else {
        this.excludes = Collections.emptyList();
    }
}
 
Example 4
Project: gcplot   File: AddJvmRequest.java   View source code 6 votes vote down vote up
public AddJvmRequest(@JsonProperty(value = "id", required = true)
                     @JsonDeserialize(using = UUIDDeserializer.class)
                     @JsonSerialize(using = UUIDSerializer.class) UUID jvmId,
                     @JsonProperty(value = "an_id", required = true) String analyseId,
                     @JsonProperty(value = "name", required = true) String jvmName,
                     @JsonProperty(value = "vm_ver", required = true) int vmVersion,
                     @JsonProperty(value = "gc_type", required = true) int gcType,
                     @JsonProperty("headers") String headers,
                     @JsonProperty("mem") MemoryStatus memoryStatus) {
    this.jvmId = jvmId;
    this.analyseId = analyseId;
    this.jvmName = jvmName;
    this.vmVersion = vmVersion;
    this.gcType = gcType;
    this.headers = headers;
    this.memoryStatus = memoryStatus;
}
 
Example 5
Project: FreeBuilder   File: JacksonSupportTest.java   View source code 6 votes vote down vote up
@Test
public void jacksonAnnotationAddedWithImplicitName() throws CannotGenerateCodeException {
  // See also https://github.com/google/FreeBuilder/issues/90
  TypeElement dataType = model.newType(
      "package com.example;",
      "@" + JsonDeserialize.class.getName() + "(builder = DataType.Builder.class)",
      "public interface DataType {",
      "  int getFooBar();",
      "  class Builder extends DataType_Builder {}",
      "}");

  Metadata metadata = analyser.analyse(dataType);

  Property property = getOnlyElement(metadata.getProperties());
  assertPropertyHasJsonPropertyAnnotation(property, "fooBar");
}
 
Example 6
Project: FreeBuilder   File: JacksonSupportTest.java   View source code 6 votes vote down vote up
@Test
public void jsonAnyGetterAnnotationDisablesImplicitProperty() throws CannotGenerateCodeException {
  TypeElement dataType = model.newType(
      "package com.example;",
      "@" + JsonDeserialize.class.getName() + "(builder = DataType.Builder.class)",
      "public interface DataType {",
      "  @" + JsonAnyGetter.class.getName(),
      "  " + Map.class.getName() + "<Integer, String> getFooBar();",
      "  class Builder extends DataType_Builder {}",
      "}");

  Metadata metadata = analyser.analyse(dataType);

  Property property = getOnlyElement(metadata.getProperties());
  assertThat(property.getAccessorAnnotations()).named("property accessor annotations").isEmpty();
}
 
Example 7
Project: GitHub   File: MediaIT.java   View source code 5 votes vote down vote up
@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());
}
 
Example 8
Project: GitHub   File: MediaIT.java   View source code 5 votes vote down vote up
@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);
    }
}
 
Example 9
Project: GitHub   File: ObjectMappedTest.java   View source code 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Test
public void noAnnotationsWorks() throws Exception {
  check(ImmutableJacksonMappedWithNoAnnotations.Json.class.getAnnotation(JsonDeserialize.class)).isNull();
  String json = "{\"someString\":\"xxx\"}";
  ImmutableJacksonMappedWithNoAnnotations value =
      OBJECT_MAPPER.readValue(json, ImmutableJacksonMappedWithNoAnnotations.class);
  check(OBJECT_MAPPER.writeValueAsString(value)).is(json);
}
 
Example 10
Project: iiif-apis   File: SearchResult.java   View source code 5 votes vote down vote up
/**
 * Set the list of containing resources. Must all be instances of {@link SearchLayer}
 *
 * @throws IllegalArgumentException if at least one of the resources is not a {@link SearchLayer}
 */
@JsonDeserialize(contentAs = SearchLayer.class)
@Override
public void setWithin(List<Resource> within) throws IllegalArgumentException {
  if (within.stream().anyMatch(r -> !(r instanceof SearchLayer))) {
    throw new IllegalArgumentException("SearchResult can only be within a SearchLayer.");
  }
  super.setWithin(within);
}
 
Example 11
Project: centraldogma   File: PasswordMirrorCredential.java   View source code 5 votes vote down vote up
@JsonCreator
public PasswordMirrorCredential(@JsonProperty("hostnamePatterns")
                                @JsonDeserialize(contentAs = Pattern.class)
                                Iterable<Pattern> hostnamePatterns,
                                @JsonProperty("username") String username,
                                @JsonProperty("password") String password) {
    super(hostnamePatterns);

    this.username = requireNonEmpty(username, "username");
    this.password = requireNonNull(password, "password");
}
 
Example 12
Project: centraldogma   File: CreateSessionCommand.java   View source code 5 votes vote down vote up
@JsonCreator
CreateSessionCommand(@JsonProperty("timestamp") @Nullable Long timestamp,
                     @JsonProperty("author") @Nullable Author author,
                     @JsonProperty("session")
                     @JsonDeserialize(using = SimpleSessionJsonDeserializer.class)
                     SimpleSession session) {

    super(CommandType.CREATE_SESSION, timestamp, author);
    this.session = requireNonNull(session, "session");
}
 
Example 13
Project: bazel-tools   File: Dependencies.java   View source code 5 votes vote down vote up
@JsonCreator
public static Dependencies create(
    @JsonProperty("options") final Options options,
    @JsonDeserialize(using = TableDeserializer.class) @JsonProperty("maven")
        final ImmutableTable<String, String, Maven> maven) {
  return builder().options(options).maven(maven == null ? ImmutableTable.of() : maven).build();
}
 
Example 14
Project: CityPower-Build-Sample   File: IncidentServiceImpl.java   View source code 5 votes vote down vote up
@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;
}
 
Example 15
Project: spring-vault   File: Policy.java   View source code 5 votes vote down vote up
@JsonCreator
private Rule(
		@JsonProperty("capabilities") List<Capability> capabilities,
		@JsonProperty("min_wrapping_ttl") @JsonDeserialize(converter = StringToDurationConverter.class) Duration minWrappingTtl,
		@JsonProperty("max_wrapping_ttl") @JsonDeserialize(converter = StringToDurationConverter.class) Duration maxWrappingTtl,
		@JsonProperty("allowed_parameters") Map<String, List<String>> allowedParameters,
		@JsonProperty("denied_parameters") Map<String, List<String>> deniedParameters) {

	this.path = "";
	this.capabilities = capabilities;
	this.minWrappingTtl = minWrappingTtl;
	this.maxWrappingTtl = maxWrappingTtl;
	this.allowedParameters = allowedParameters;
	this.deniedParameters = deniedParameters;
}
 
Example 16
Project: jacksync   File: PatchPathOperation.java   View source code 5 votes vote down vote up
/**
 * @param path the path to set
 */
@JsonDeserialize(using = JsonPointerDeserializer.class)
public void setPath(JsonPointer path) {
       if (path == null) {
           throw new IllegalArgumentException("Path is null");
       }
	this.path = path;
}
 
Example 17
Project: jacksync   File: PatchDualPathOperation.java   View source code 5 votes vote down vote up
/**
 * @param from the from to set
 */
@JsonDeserialize(using = JsonPointerDeserializer.class)
public void setFrom(JsonPointer from) {
       if (from == null) {
           throw new IllegalArgumentException("From is null");
       }
	this.from = from;
}
 
Example 18
Project: camino   File: Repeat.java   View source code 5 votes vote down vote up
/**
 * Constructor
 *
 * @param var name of variable
 * @param list list to iterate over
 * @param paths list of paths
 */
@JsonCreator
public Repeat(@JsonProperty("var") String var, @JsonProperty("list") String list,
		@JsonProperty("paths") @JsonDeserialize(contentAs = Path.class) List<Path> paths,
		@JsonProperty("repeats") @JsonDeserialize(contentAs = Repeat.class)	List<Repeat> repeats) {
	this.var = var;
	this.list = list;
	this.paths = ImmutableList.copyOf(paths != null ? paths : Collections.emptyList());
	this.repeats = ImmutableList.copyOf(repeats != null ? repeats :
			Collections.emptyList());
}
 
Example 19
Project: camino   File: Config.java   View source code 5 votes vote down vote up
/**
 * Constructor
 */
@JsonCreator
public Config(@JacksonInject("location") URI location,
		@JsonProperty("includes") List<String> includes,
		@JsonProperty("properties") @JsonDeserialize(as = LinkedHashMap.class, keyAs = String.class,
				contentAs = String.class) Map<String, String> properties,
		@JsonProperty("paths") @JsonDeserialize(contentAs = Path.class)	List<Path> paths,
		@JsonProperty("repeats") @JsonDeserialize(contentAs = Repeat.class) List<Repeat> repeats) {
	this(location, includes, properties == null ? null : ConfigUtil.mapToList(properties,
			Property::new),
			paths, repeats);
}
 
Example 20
Project: camino   File: Path.java   View source code 5 votes vote down vote up
/**
 * Constructor
 *
 * @param name name of path
 * @param value value of path
 * @param metrics metrics under this path
 * @param tags tags of this path as ordered map of tag key/value pairs
 * @param expectedCreationTime expression to calculate creation time of this path
 */
@JsonCreator
public Path(@JsonProperty("name") String name, @JsonProperty("value") String value,
		@JsonProperty("metrics") @JsonDeserialize(contentAs = Metric.class) List<Metric> metrics,
		@JsonProperty("tags") @JsonDeserialize(as = LinkedHashMap.class, keyAs = String.class,
				contentAs = String.class) Map<String, String> tags,
		@JsonProperty("expectedCreationTime") String expectedCreationTime) {
	this(name, value, metrics, tags == null ? null : ConfigUtil.mapToList(tags,
			Tag::new), expectedCreationTime);
}
 
Example 21
Project: cineast   File: RetrieverConfig.java   View source code 5 votes vote down vote up
@JsonProperty("features")
@JsonDeserialize(contentUsing = FeatureCategoriesDeserializer.class)
public List<String> getRetrieverCategories(){
	Set<String> keys = this.retrieverCategories.keySet();
	ArrayList<String> _return = new ArrayList<>(keys.size());
	_return.addAll(keys);
	return _return;
}
 
Example 22
Project: haven-platform   File: JobParameters.java   View source code 5 votes vote down vote up
@JsonDeserialize(contentUsing = JobParametersDeserializer.class)
public void setParameters(Map<String, Object> parameters) {
    this.parameters.clear();
    if(parameters != null) {
        this.parameters.putAll(parameters);
    }
}
 
Example 23
Project: vespa   File: InstanceConfirmation.java   View source code 5 votes vote down vote up
@JsonCreator
public InstanceConfirmation(@JsonProperty("provider") String provider,
                            @JsonProperty("domain") String domain,
                            @JsonProperty("service") String service,
                            @JsonProperty("attestationData") @JsonDeserialize(using = SignedIdentityDeserializer.class)
                                        SignedIdentityDocument signedIdentityDocument) {
    this.provider = provider;
    this.domain = domain;
    this.service = service;
    this.signedIdentityDocument = signedIdentityDocument;
}
 
Example 24
Project: dhis2-core   File: DataInputPeriod.java   View source code 5 votes vote down vote up
@JsonProperty
@JsonSerialize( using = JacksonPeriodSerializer.class )
@JsonDeserialize( using = JacksonPeriodDeserializer.class )
@JacksonXmlProperty( localName = "period", namespace = DxfNamespaces.DXF_2_0 )
public Period getPeriod()
{
    return period;
}
 
Example 25
Project: dhis2-core   File: DataSet.java   View source code 5 votes vote down vote up
@JsonProperty
@JsonSerialize( using = JacksonPeriodTypeSerializer.class )
@JsonDeserialize( using = JacksonPeriodTypeDeserializer.class )
@JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
@Property( PropertyType.TEXT )
public PeriodType getPeriodType()
{
    return periodType;
}
 
Example 26
Project: dhis2-core   File: ValidationRule.java   View source code 5 votes vote down vote up
@JsonProperty
@JsonSerialize( using = JacksonPeriodTypeSerializer.class )
@JsonDeserialize( using = JacksonPeriodTypeDeserializer.class )
@JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
@Property( PropertyType.TEXT )
public PeriodType getPeriodType()
{
    return periodType;
}
 
Example 27
Project: dhis2-core   File: EventChart.java   View source code 5 votes vote down vote up
@Override
@JsonProperty
@JsonDeserialize( as = BaseDimensionalItemObject.class )
@JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
public DimensionalItemObject getValue()
{
    return value;
}
 
Example 28
Project: dhis2-core   File: Predictor.java   View source code 5 votes vote down vote up
@JsonProperty
@JsonSerialize( using = JacksonPeriodTypeSerializer.class )
@JsonDeserialize( using = JacksonPeriodTypeDeserializer.class )
@JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
@Property( PropertyType.TEXT )
public PeriodType getPeriodType()
{
    return periodType;
}
 
Example 29
Project: dhis2-core   File: Program.java   View source code 5 votes vote down vote up
@JsonProperty
@JsonSerialize( using = JacksonPeriodTypeSerializer.class )
@JsonDeserialize( using = JacksonPeriodTypeDeserializer.class )
@JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
public PeriodType getExpiryPeriodType()
{
    return expiryPeriodType;
}
 
Example 30
Project: dhis2-core   File: ProgramStage.java   View source code 5 votes vote down vote up
@JsonProperty
@JsonSerialize( using = JacksonPeriodTypeSerializer.class )
@JsonDeserialize( using = JacksonPeriodTypeDeserializer.class )
@JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
@Property( PropertyType.TEXT )
public PeriodType getPeriodType()
{
    return periodType;
}
 
Example 31
Project: dhis2-core   File: DataApprovalWorkflow.java   View source code 5 votes vote down vote up
@JsonProperty
@JsonSerialize( using = JacksonPeriodTypeSerializer.class )
@JsonDeserialize( using = JacksonPeriodTypeDeserializer.class )
@JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
@Property( PropertyType.TEXT )
public PeriodType getPeriodType()
{
    return periodType;
}
 
Example 32
Project: dhis2-core   File: EventReport.java   View source code 5 votes vote down vote up
@Override
@JsonProperty
@JsonDeserialize( as = BaseDimensionalItemObject.class )
@JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
public DimensionalItemObject getValue()
{
    return value;
}
 
Example 33
Project: dhis2-core   File: BaseAnalyticalObject.java   View source code 5 votes vote down vote up
@JsonProperty
@JsonSerialize( contentUsing = JacksonPeriodSerializer.class )
@JsonDeserialize( contentUsing = JacksonPeriodDeserializer.class )
@JacksonXmlElementWrapper( localName = "periods", namespace = DxfNamespaces.DXF_2_0 )
@JacksonXmlProperty( localName = "period", namespace = DxfNamespaces.DXF_2_0 )
public List<Period> getPeriods()
{
    return periods;
}
 
Example 34
Project: dhis2-core   File: BaseAnalyticalObject.java   View source code 5 votes vote down vote up
@Override
@JsonProperty
@JsonDeserialize( contentAs = BaseDimensionalObject.class )
@JacksonXmlElementWrapper( localName = "columns", namespace = DxfNamespaces.DXF_2_0 )
@JacksonXmlProperty( localName = "column", namespace = DxfNamespaces.DXF_2_0 )
public List<DimensionalObject> getColumns()
{
    return columns;
}
 
Example 35
Project: dhis2-core   File: BaseAnalyticalObject.java   View source code 5 votes vote down vote up
@Override
@JsonProperty
@JsonDeserialize( contentAs = BaseDimensionalObject.class )
@JacksonXmlElementWrapper( localName = "rows", namespace = DxfNamespaces.DXF_2_0 )
@JacksonXmlProperty( localName = "row", namespace = DxfNamespaces.DXF_2_0 )
public List<DimensionalObject> getRows()
{
    return rows;
}
 
Example 36
Project: dhis2-core   File: BaseAnalyticalObject.java   View source code 5 votes vote down vote up
@Override
@JsonProperty
@JsonDeserialize( contentAs = BaseDimensionalObject.class )
@JacksonXmlElementWrapper( localName = "filters", namespace = DxfNamespaces.DXF_2_0 )
@JacksonXmlProperty( localName = "filter", namespace = DxfNamespaces.DXF_2_0 )
public List<DimensionalObject> getFilters()
{
    return filters;
}
 
Example 37
Project: dhis2-core   File: BaseIdentifiableObject.java   View source code 5 votes vote down vote up
@JsonProperty
@JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
@JsonSerialize( using = CustomLastUpdatedUserSerializer.class )
@JsonDeserialize
public User getLastUpdatedBy()
{
    return  lastUpdatedBy;
}
 
Example 38
Project: dhis2-core   File: BaseDimensionalObject.java   View source code 5 votes vote down vote up
@Override
@JsonProperty
@JsonDeserialize( contentAs = BaseDimensionalItemObject.class )
@JacksonXmlElementWrapper( localName = "items", namespace = DxfNamespaces.DXF_2_0 )
@JacksonXmlProperty( localName = "item", namespace = DxfNamespaces.DXF_2_0 )
public List<DimensionalItemObject> getItems()
{
    return items;
}
 
Example 39
Project: dhis2-core   File: Period.java   View source code 5 votes vote down vote up
@JsonProperty
@JsonSerialize( using = JacksonPeriodTypeSerializer.class )
@JsonDeserialize( using = JacksonPeriodTypeDeserializer.class )
@JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
@Property( PropertyType.TEXT )
public PeriodType getPeriodType()
{
    return periodType;
}
 
Example 40
Project: archie   File: DvTime.java   View source code 5 votes vote down vote up
@Override
//    @XmlElements({
//            @XmlElement(type=OffsetTime.class),
//            @XmlElement(type=LocalTime.class)
//    })    
    @JsonDeserialize(using=TimeDeserializer.class)
    public TemporalAccessor getValue() {
        return value;
    }