Вот моя модель:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.dwidasa.kse.ksei.model;
/**
*
* @author asus
*/
public class ParticipantMsg {
private String participantCode;
private String ktpNumber;
private String namaLengkap;
private String tanggalLahir;
private String jenisKelamin;
private String noRekeningInvestor;
private String nationality;
private String tipeInvestor;
private String reason;
public String getParticipantCode() {
return participantCode;
}
public void setParticipantCode(String participantCode) {
this.participantCode = participantCode;
}
public String getKtpNumber() {
return ktpNumber;
}
public void setKtpNumber(String ktpNumber) {
this.ktpNumber = ktpNumber;
}
public String getNamaLengkap() {
return namaLengkap;
}
public void setNamaLengkap(String namaLengkap) {
this.namaLengkap = namaLengkap;
}
public String getTanggalLahir() {
return tanggalLahir;
}
public void setTanggalLahir(String tanggalLahir) {
this.tanggalLahir = tanggalLahir;
}
public String getJenisKelamin() {
return jenisKelamin;
}
public void setJenisKelamin(String jenisKelamin) {
this.jenisKelamin = jenisKelamin;
}
public String getNoRekeningInvestor() {
return noRekeningInvestor;
}
public void setNoRekeningInvestor(String noRekeningInvestor) {
this.noRekeningInvestor = noRekeningInvestor;
}
public String getNationality() {
return nationality;
}
public void setNationality(String nationality) {
this.nationality = nationality;
}
public String getTipeInvestor() {
return tipeInvestor;
}
public void setTipeInvestor(String tipeInvestor) {
this.tipeInvestor = tipeInvestor;
}
public String getReason() {
return reason;
}
public void setReason(String reason) {
this.reason = reason;
}
}
Вот мой код сервера:
package com.dwidasa.ib.services;
import com.dwidasa.engine.json.PojoJsonMapper;
import com.dwidasa.ib.annotations.NoValidate;
import com.dwidasa.kse.ksei.model.ParticipantMsg;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import org.jboss.resteasy.annotations.cache.NoCache;
import org.springframework.web.bind.annotation.RequestBody;
@Path("/dukcapil")
@NoCache
public abstract interface KSEIDukcapilResource
{
@NoValidate
@POST
@Produces({"application/json;charset=utf-8"})
@Consumes("application/json")
@Path("inquiryKSEI")
public abstract String inquiryNIK(@Context HttpServletRequest paramHttpServletRequest,
@RequestBody ParticipantMsg msg);
}
Вот мой код читателя сообщения:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.dwidasa.kse.ksei.service;
import com.dwidasa.kse.ksei.model.ParticipantMsg;
import javax.ws.rs.Consumes;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.ext.MessageBodyReader;
import javax.ws.rs.ext.Provider;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import java.io.*;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
/**
*
* @author asus
*/
@Provider
@Consumes("application/json")
public class ParticipantBodyReader implements MessageBodyReader<ParticipantMsg> {
@Override
public boolean isReadable(Class<?> type, Type genericType,
Annotation[] annotations, MediaType mediaType) {
return type == ParticipantMsg.class;
}
@Override
public ParticipantMsg readFrom(Class<ParticipantMsg> type, Type genericType, Annotation[] annotations,
MediaType mediaType, MultivaluedMap<String, String> httpHeaders,
InputStream entityStream) throws IOException, WebApplicationException {
try {
JAXBContext jaxbContext = JAXBContext.newInstance(ParticipantMsg.class);
return (ParticipantMsg) jaxbContext.createUnmarshaller().unmarshal(entityStream);
} catch (JAXBException e) {
// throw new ProcessingException("Error deserializing user.", e);
throw new WebApplicationException(e);
}
}
}
Я делаю RESTAPI в качестве сервера, но когда я ударил почтальона, всегда получалась ошибка. "org.jboss.resteasy.spi.BadRequestException: Не удалось найти устройство чтения тела сообщения для типа: класс com.dwidasa.kse.ksei.model.ParticipantMsg типа содержимого: application / json"?