Hello. I am using Jira Server and have some trouble with deserialization.
I understand, that I need something like this https://www.baeldung.com/jackson-inheritance , but when I try it, a catch exception: "problem: abstract types can only be instantiated with additional type information".
I have an abstract class Vehicle:
import org.codehaus.jackson.annotate.JsonSubTypes;
import org.codehaus.jackson.annotate.JsonSubTypes.Type;
import org.codehaus.jackson.annotate.JsonTypeInfo;
import javax.xml.bind.annotation.XmlRootElement;
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
include = JsonTypeInfo.As.PROPERTY,
property = "type")
@JsonSubTypes({
@Type(value = Car.class, name = "car"),
@Type(value = Truck.class, name = "truck")
})
@XmlRootElement
public abstract class Vehicle {}
Class Car:
@XmlRootElement
public class Car extends Vehicle {
@XmlElement
private String model;
public Car(String model) {
this.model = model;
}
// no-arg constructor, getters and setters
}
And class Truck:
@XmlRootElement
public class Truck extends Vehicle {
@XmlElement
private String price;
public Truck(String price) {
this.model = model;
}
// no-arg constructor, getters and setters
}
My Rest class has a method:
@POST
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
public Response test(Vehicle vehicle) {
Vehicle vehicleTest = vehicle;
return Response.ok(vehicle).build();
}
And I sending ajax from front-part (jQuery) :
test = function(){
var vehicle= {
type: "car",
model: "BMW"
};
return $.ajax({
type: "POST",
data: JSON.stringify(vehicle),
url: instance.path,
contentType: "application/json; charset=utf-8",
dataType: 'json',
mimeType: 'application/json'
})
};
I expected to receive Car in my rest module, but catch the exception: "problem: abstract types can only be instantiated with additional type information". I assume that either the annotations were used incorrectly or the JSON was incorrectly compiled. Either the error is small, or the Jira uses a completely different approach.
The request to prompt - in what way it is possible to solve the existing problem.
Thanks.
Hey Oleksii,
Exciting that you're developing on Jira Server! I must admit my Java is a little rusty (and I don't mean Rust), so I don't have a straightforward answer for you about this.
We do however have a dedicated Developer Community that might be good to check out for plugin development related questions. Since the topics are more focused, it's easier for other developers to watch the questions coming in and provide guidance. I would try asking there, as the general Community here is a little more targeted at general users and administrators. Plus, the topics on the Developer Community are also very interesting to read!
Cheers,
Daniel | Atlassian Support
Thanks for your advice, Daniel. I will ask there.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.