# Java deserializing problem with oneOf

**URL:** <https://community.hubspot.com/t/java-deserializing-problem-with-oneof/61989>\
**Category:** APIs & Integrations\
**Created:** [July 29, 2022, 12:33pm UTC](https://community.hubspot.com/t/java-deserializing-problem-with-oneof/61989 "2022-07-29T12:33:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![TLysek](https://avatars.discourse-cdn.com/v4/letter/t/b5a626/32.png) [@TLysek](https://community.hubspot.com/u/TLysek)\
**Post date:** [July 29, 2022, 12:33pm UTC](https://community.hubspot.com/t/java-deserializing-problem-with-oneof/61989/1 "2022-07-29T12:33:12Z")

</div>

I have problem with /api-catalog-public/v1/apis/marketing/v3/forms .  
I used Swagger Codegen to generate Java classes (OpenAPI Generator does not work, problem with StackOverflowError, circular dependencies).  
I’m trying to call [Accounts Dashboard | HubSpot](https://developers.hubspot.com/docs/api/marketing/forms) “GET form definition” [https://api.hubapi.com/marketing/v3/forms/{{formId}}](https://api.hubapi.com/marketing/v3/forms/%7B%7BformId%7D%7D)  
and deserialize it and there is a problem with Jackson (Spring Boot app):

```auto
org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Could not resolve subtype of [simple type, class com.hubapi.api.model.forms.HubSpotFormDefinition]: missing type id property 'type'; nested exception is com.fasterxml.jackson.databind.exc.InvalidTypeIdException: Could not resolve subtype of [simple type, class com.hubapi.api.model.forms.HubSpotFormDefinition]: missing type id property 'type'
 at [Source: (PushbackInputStream); line: 1, column: 4185]

```

_And there is no property **type** in response from API. Why?_

I think something wrong could be with generated class:

```lia-code-sample
package com.hubapi.api.model.forms;

import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
/**
* OneOfFormDefinitionBase
*/
@JsonTypeInfo(
 use = JsonTypeInfo.Id.NAME,
 include = JsonTypeInfo.As.PROPERTY,
 property = "type")
@JsonSubTypes({
 @JsonSubTypes.Type(value = HubSpotFormDefinition.class, name = "HubSpotFormDefinition")
})
public interface OneOfFormDefinitionBase {

}

```

BTW: What is this? It’s part of HubSpotFormDefinition definition in API.

```auto
 "x-hubspot-java-type-name" : "com.hubspot.forms.external.core.models.forms.HubSpotFormDefinition",
 "x-hubspot-external-project-origin" : false,
 "x-hubspot-sub-type-impl" : true

```

The same problem is with:

```lia-code-sample
@JsonTypeInfo(
 use = JsonTypeInfo.Id.NAME,
 include = JsonTypeInfo.As.PROPERTY,
 property = "type")
@JsonSubTypes({
 @JsonSubTypes.Type(value = EmailField.class, name = "EmailField"),
 @JsonSubTypes.Type(value = PhoneField.class, name = "PhoneField"),
 @JsonSubTypes.Type(value = MobilePhoneField.class, name = "MobilePhoneField"),
 @JsonSubTypes.Type(value = SingleLineTextField.class, name = "SingleLineTextField"),
 @JsonSubTypes.Type(value = MultiLineTextField.class, name = "MultiLineTextField"),
 @JsonSubTypes.Type(value = NumberField.class, name = "NumberField"),
 @JsonSubTypes.Type(value = SingleCheckboxField.class, name = "SingleCheckboxField"),
 @JsonSubTypes.Type(value = MultipleCheckboxesField.class, name = "MultipleCheckboxesField"),
 @JsonSubTypes.Type(value = DropdownField.class, name = "DropdownField"),
 @JsonSubTypes.Type(value = RadioField.class, name = "RadioField"),
 @JsonSubTypes.Type(value = DatepickerField.class, name = "DatepickerField"),
 @JsonSubTypes.Type(value = FileField.class, name = "FileField")
})
public interface OneOfFieldGroupFieldsItems {

}

```

```lia-code-sample
 "fields" : {
 "type" : "array",
 "description" : "The form fields included in the group",
 "items" : {
 "oneOf" : [ {
 "$ref" : "#/components/schemas/EmailField"
 }, {
 "$ref" : "#/components/schemas/PhoneField"
 }, {
 "$ref" : "#/components/schemas/MobilePhoneField"
 }, {
 "$ref" : "#/components/schemas/SingleLineTextField"
 }, {
 "$ref" : "#/components/schemas/MultiLineTextField"
 }, {
 "$ref" : "#/components/schemas/NumberField"
 }, {
 "$ref" : "#/components/schemas/SingleCheckboxField"
 }, {
 "$ref" : "#/components/schemas/MultipleCheckboxesField"
 }, {
 "$ref" : "#/components/schemas/DropdownField"
 }, {
 "$ref" : "#/components/schemas/RadioField"
 }, {
 "$ref" : "#/components/schemas/DatepickerField"
 }, {
 "$ref" : "#/components/schemas/FileField"
 } ]
 }
 }

```

How does the deserializer can be aware of what type of field is receiving?

I would like to try the same with stable v2 FORMS API but I couldn’t fine OpenAPI link to contract and generate classes from it 😞

---

<div class="post-metadata">

**Author:** ![Jaycee\_Lewis](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jaycee_lewis/32/61352_2.png) [@Jaycee\_Lewis](https://community.hubspot.com/u/Jaycee_Lewis)\
**Post date:** [August 1, 2022, 4:47pm UTC](https://community.hubspot.com/t/java-deserializing-problem-with-oneof/61989/2 "2022-08-01T16:47:21Z")

</div>

Hi, [@TŁysek](https://community.hubspot.com/t5/user/viewprofilepage/user-id/425765) 👋 Let’s see if we can get the conversation started. Hey, @lbkulinski @piersg do you have any Java experience here?

Thank you! — Jaycee
