1

My Javascript code:

 function singleCopySave() { var sam1="00:A0:C9:14:C8:29"; var mac=toLrad.split(":").map(Integer.parseInt(_,16)).foldLeft(0L) {case (acc,item) => acc*256+item}; var JSONObject = {}; JSONObject["toLrad"]=sam1; var jsonData=dojo.toJson(JSONObject); dojo.xhrPost({ url :"/unified/singleCopy", preventCache:true, handleAs: "text", postData:jsonData, headers: {"Content-Type": "application/json"}, sync:true, load: function(response, ioArgs) { retVal = response; }, error: function(errorResponse, ioArgs) { } }); } 

My Java REST code looks like below:

@POST @Path("/singleCopy") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.TEXT_PLAIN) public String singleApCopy(sampleDTO dto,@Context HttpServletRequest request, @Context HttpServletResponse response) { long toLradId = dto.getToLrad(); return "success"; 

It is not hitting the REST url. There's a mistake in converting the string value to long. Could someone please help me out the syntax problem in converting to long? Or is there a way to convert the mac address in the DTO.java ?

2
  • a mac address is 6 x 2 hex digits ... you have 4 ... and you have a v - which isn't hex Commented Feb 7, 2017 at 4:11
  • @JaromandaX That is just a sample. I have the right MAC address passed. I have changed it accordingly. Commented Feb 7, 2017 at 4:48

1 Answer 1

4

try this

var mac= parseInt(sam1.split(':').join(''), 16); var JSONObject = {}; JSONObject["toLrad"]=mac; 

you must send json property toLrad as long, it will able to convert in Java method

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.