POST 메서드를 수행하려고하는 JS 파일이 있지만 입력으로 특정 Java 객체가 필요합니다. 여기 각도 JS에서 Java 객체를 보내는 방법
서버에서 찾는 방법의 서명이다 여기@Path("/branches")
public class BranchResource {
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response post(BranchDescriptor branch) {
.
.
인 I는 다음의 에러 수신 된
$scope.retry = function() {
$http({
url : "rest/branches",
method : "POST",
dataType : "json",//not sure is needed
data : "way to get Branch descriptor "
headers : {
"Content-Type" : "application/json; charset=utf-8",
"Accept" : "application/json"
}
}).success(function(data) {
$scope.items = data;
}).error(function(data) {
alert('err');
});
};
(각도 사용) JS 기능 :
을??? 27, 2014 3:27:48 PM com.sun.jersey.spi.container.ContainerRequest getEntity
SEVERE: A message body reader for Java class xxx.api.BranchDescriptor, and Java type class xxx.BranchDescriptor, and MIME media type application/octet-stream was not found.
The registered message body readers compatible with the MIME media type are:
application/octet-stream ->
com.sun.jersey.core.impl.provider.entity.ByteArrayProvider
com.sun.jersey.core.impl.provider.entity.FileProvider
com.sun.jersey.core.impl.provider.entity.InputStreamProvider
com.sun.jersey.core.impl.provider.entity.DataSourceProvider
com.sun.jersey.core.impl.provider.entity.RenderedImageProvider
*/* ->
이렇게 데이터를 추가하려고했습니다.
data : { "_protectedBranch" : "pf_something", "_newBranch" : "some_branch", "_commitId" : "some_commit", "_commiter" : "someone" },
다음과 같은 오류 있어요 :
이??? 27, 2014 3:42:46 PM com.sun.jersey.spi.container.ContainerResponse mapMappableContainerException
SEVERE: The exception contained within MappableContainerException could not be mapped to a response, re-throwing to the HTTP container
org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field "_protectedBranch" (Class xxx.BranchDescriptor), not marked as ignorable
at [Source: [email protected]; line: 1, column: 22] (through reference chain: xxx.BranchDescriptor["_protectedBranch"])
at org.codehaus.jackson.map.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:53)
가 어떻게 전송을위한 BranchDescriptor 개체를 전달할 수 있습니까? 내가 무엇이 누락 되었습니까?
당신이하려는 것은별로 의미가 없습니다. 자바 객체를 (적어도 클라이언트 측에서) JS로 생성 할 수 없다. Java와 JavaScript에는 공통점이 없습니다. REST 서비스를 사용하고 Java 기능에 필요한 특성을 전달한 다음 Java 서버 코드 내에서 오브젝트를 작성하는 것입니다. – dirkk
또한 콘솔에서 오류를 공유 할 수 있습니다. – Jai
질문은 어떻게 든 오도하는 것입니다. 재건하려고 노력하십시오. –