Maven Project ile bir Jersey Server yapıyorum ve C# programından bir İstek göndermeye çalıştığım durumlar dışında her şeyin iyi çalıştığını biliyorum. Kullanıcının, olarak JSON görünür: Ben boş bir Java Array ile bitirmek sunucuya kodu gönderdiğinizdeJSON Dizisi Jersey'de Eşleşmiyor
[{"Weight":0.0,"RFIDCode":0},{"Weight":55.5,"RFIDCode":1}]
Benim C# kodu
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using System.IO;
using RestSharp;
namespace POSTJSONList
{
class Program
{
static void Main(string[] args)
{
List<ExampleMen> people = new List<ExampleMen>();
JsonSerializer ser = new JsonSerializer();
for (int i = 0; i < 5; i++)
{
ExampleMen person1 = new ExampleMen(i, i * 55.5);
people.Add(person1);
}
string json = JsonConvert.SerializeObject(people);
Console.WriteLine(json);
Console.ReadLine();
var client = new RestClient("http://localhost:9998");
var request = new RestRequest("/trash", Method.POST);
request.AddJsonBody(json);
client.ExecuteAsync(request, response => {
Console.WriteLine(response.Content);
});
Console.ReadLine();
}
}
}
Benim Java code altındadır
altındadır 210@POST
@Produces("application/json")
@Consumes(MediaType.APPLICATION_JSON)
//@Param recycleList a list of all of the data that we have collected
public String createtrash_records(trashpickup_type trashList[]){
System.out.println("Im Here Guys!!!!");
// TODO update this to take the information we pass through to it and create individual objects based on it.
// TODO modify to return success code
billing billSystem = billing.getInstance();
systemTotalsTrash sysTotalsTrashSystem = systemTotalsTrash.getInstance();
int i = 1;
for(trashpickup_type alpha : trashList)
{
System.out.println(alpha.getRFIDCode() + alpha.getWeight());
i++;
/*try {
billSystem.updateBillingRecord(rec.getUserName(), 0, rec.getWeight());
sysTotalsTrashSystem.updateSystemTotals(rec.getWeight());
getDao().createIfNotExists(rec);
} catch (SQLException e) {
e.printStackTrace();
}
*/
}
return "It worked";
}
(JSON eşleştirilmiş olduğu) Model Kodu
package com.gallup.gethip.model;
import java.util.Date;
import javax.xml.bind.annotation.XmlRootElement;
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;
@XmlRootElement
@DatabaseTable(tableName="trash_records")
public class trashpickup_type {
@DatabaseField(columnName = "RFIDCode")
private int RFIDCode;
@DatabaseField(columnName = "Weight")
private double Weight;
@DatabaseField(columnName = "PickedUp")
private Date PickedUp;
public trashpickup_type()
{
}
public void setRFIDCode(int RFIDCode)
{
this.RFIDCode = RFIDCode;
}
public void setWeight(double Weight)
{
this.Weight = Weight;
}
public void setPickedUP(Date PickedUp)
{
this.PickedUp = PickedUp;
}
public double getWeight()
{
return Weight;
}
public double getRFIDCode()
{
return RFIDCode;
}
public Date getPickedUp()
{
return PickedUp;
}
}
Herhangi Öneriler takdir edilmektedir burasıdır. Gerekirse istek üzerine daha fazla bilgi yayınlayacağım.