Browse Source

重写适合.net的参数序列化方法

qianyi
shanji 3 years ago
parent
commit
80f84f6bd4
  1. 4
      BBWY.1688SDK/BBWY.1688SDK.csproj
  2. 36
      BBWY.1688SDK/example/param/apiexample/ExampleFamily.cs
  3. 18
      BBWY.1688SDK/example/param/apiexample/ExampleFamilyPostParam.cs
  4. 24
      BBWY.1688SDK/example/param/apiexample/ExampleHouse.cs
  5. 2
      BBWY.1688SDK/serialize/Json2Deserializer.cs
  6. 27
      BBWY.1688SDK/serialize/Param2RequestSerializer.cs

4
BBWY.1688SDK/BBWY.1688SDK.csproj

@ -5,4 +5,8 @@
<RootNamespace>BBWY._1688SDK</RootNamespace> <RootNamespace>BBWY._1688SDK</RootNamespace>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>
</Project> </Project>

36
BBWY.1688SDK/example/param/apiexample/ExampleFamily.cs

@ -19,7 +19,8 @@ namespace com.alibaba.china.openapi.client.example.param.apiexample
/** /**
* @return * @return
*/ */
public int? getFamilyNumber() { public int? getFamilyNumber()
{
return familyNumber; return familyNumber;
} }
@ -28,7 +29,8 @@ namespace com.alibaba.china.openapi.client.example.param.apiexample
* <pre></pre> * <pre></pre>
* *
*/ */
public void setFamilyNumber(int familyNumber) { public void setFamilyNumber(int familyNumber)
{
this.familyNumber = familyNumber; this.familyNumber = familyNumber;
} }
@ -38,7 +40,8 @@ namespace com.alibaba.china.openapi.client.example.param.apiexample
/** /**
* @return * @return
*/ */
public ExamplePerson getFather() { public ExamplePerson getFather()
{
return father; return father;
} }
@ -47,7 +50,8 @@ namespace com.alibaba.china.openapi.client.example.param.apiexample
* <pre></pre> * <pre></pre>
* *
*/ */
public void setFather(ExamplePerson father) { public void setFather(ExamplePerson father)
{
this.father = father; this.father = father;
} }
@ -57,7 +61,8 @@ namespace com.alibaba.china.openapi.client.example.param.apiexample
/** /**
* @return * @return
*/ */
public ExamplePerson getMother() { public ExamplePerson getMother()
{
return mother; return mother;
} }
@ -66,7 +71,8 @@ namespace com.alibaba.china.openapi.client.example.param.apiexample
* <pre></pre> * <pre></pre>
* *
*/ */
public void setMother(ExamplePerson mother) { public void setMother(ExamplePerson mother)
{
this.mother = mother; this.mother = mother;
} }
@ -76,7 +82,8 @@ namespace com.alibaba.china.openapi.client.example.param.apiexample
/** /**
* @return * @return
*/ */
public ExamplePerson[] getChildren() { public ExamplePerson[] getChildren()
{
return children; return children;
} }
@ -85,7 +92,8 @@ namespace com.alibaba.china.openapi.client.example.param.apiexample
* <pre></pre> * <pre></pre>
* *
*/ */
public void setChildren(ExamplePerson[] children) { public void setChildren(ExamplePerson[] children)
{
this.children = children; this.children = children;
} }
@ -95,7 +103,8 @@ namespace com.alibaba.china.openapi.client.example.param.apiexample
/** /**
* @return * @return
*/ */
public ExampleCar[] getOwnedCars() { public ExampleCar[] getOwnedCars()
{
return ownedCars; return ownedCars;
} }
@ -104,7 +113,8 @@ namespace com.alibaba.china.openapi.client.example.param.apiexample
* <pre></pre> * <pre></pre>
* *
*/ */
public void setOwnedCars(ExampleCar[] ownedCars) { public void setOwnedCars(ExampleCar[] ownedCars)
{
this.ownedCars = ownedCars; this.ownedCars = ownedCars;
} }
@ -114,7 +124,8 @@ namespace com.alibaba.china.openapi.client.example.param.apiexample
/** /**
* @return * @return
*/ */
public ExampleHouse getMyHouse() { public ExampleHouse getMyHouse()
{
return myHouse; return myHouse;
} }
@ -123,7 +134,8 @@ namespace com.alibaba.china.openapi.client.example.param.apiexample
* <pre></pre> * <pre></pre>
* *
*/ */
public void setMyHouse(ExampleHouse myHouse) { public void setMyHouse(ExampleHouse myHouse)
{
this.myHouse = myHouse; this.myHouse = myHouse;
} }

18
BBWY.1688SDK/example/param/apiexample/ExampleFamilyPostParam.cs

@ -19,7 +19,8 @@ namespace com.alibaba.china.openapi.client.example.param.apiexample
/** /**
* @return Family对象信息 * @return Family对象信息
*/ */
public ExampleFamily getFamily() { public ExampleFamily getFamily()
{
return family; return family;
} }
@ -28,7 +29,8 @@ namespace com.alibaba.china.openapi.client.example.param.apiexample
* <pre></pre> * <pre></pre>
* *
*/ */
public void setFamily(ExampleFamily family) { public void setFamily(ExampleFamily family)
{
this.family = family; this.family = family;
} }
@ -38,7 +40,8 @@ namespace com.alibaba.china.openapi.client.example.param.apiexample
/** /**
* @return * @return
*/ */
public string getComments() { public string getComments()
{
return comments; return comments;
} }
@ -47,7 +50,8 @@ namespace com.alibaba.china.openapi.client.example.param.apiexample
* <pre></pre> * <pre></pre>
* *
*/ */
public void setComments(string comments) { public void setComments(string comments)
{
this.comments = comments; this.comments = comments;
} }
@ -57,7 +61,8 @@ namespace com.alibaba.china.openapi.client.example.param.apiexample
/** /**
* @return * @return
*/ */
public byte[] getHouseImg() { public byte[] getHouseImg()
{
return houseImg; return houseImg;
} }
@ -66,7 +71,8 @@ namespace com.alibaba.china.openapi.client.example.param.apiexample
* <pre></pre> * <pre></pre>
* *
*/ */
public void setHouseImg(byte[] houseImg) { public void setHouseImg(byte[] houseImg)
{
this.houseImg = houseImg; this.houseImg = houseImg;
} }

24
BBWY.1688SDK/example/param/apiexample/ExampleHouse.cs

@ -19,7 +19,8 @@ namespace com.alibaba.china.openapi.client.example.param.apiexample
/** /**
* @return * @return
*/ */
public string getLocation() { public string getLocation()
{
return location; return location;
} }
@ -28,7 +29,8 @@ namespace com.alibaba.china.openapi.client.example.param.apiexample
* <pre></pre> * <pre></pre>
* *
*/ */
public void setLocation(string location) { public void setLocation(string location)
{
this.location = location; this.location = location;
} }
@ -38,7 +40,8 @@ namespace com.alibaba.china.openapi.client.example.param.apiexample
/** /**
* @return * @return
*/ */
public int? getAreaSize() { public int? getAreaSize()
{
return areaSize; return areaSize;
} }
@ -47,7 +50,8 @@ namespace com.alibaba.china.openapi.client.example.param.apiexample
* <pre></pre> * <pre></pre>
* *
*/ */
public void setAreaSize(int areaSize) { public void setAreaSize(int areaSize)
{
this.areaSize = areaSize; this.areaSize = areaSize;
} }
@ -57,7 +61,8 @@ namespace com.alibaba.china.openapi.client.example.param.apiexample
/** /**
* @return * @return
*/ */
public bool? getRent() { public bool? getRent()
{
return rent; return rent;
} }
@ -66,7 +71,8 @@ namespace com.alibaba.china.openapi.client.example.param.apiexample
* <pre></pre> * <pre></pre>
* *
*/ */
public void setRent(bool rent) { public void setRent(bool rent)
{
this.rent = rent; this.rent = rent;
} }
@ -76,7 +82,8 @@ namespace com.alibaba.china.openapi.client.example.param.apiexample
/** /**
* @return * @return
*/ */
public int? getRooms() { public int? getRooms()
{
return rooms; return rooms;
} }
@ -85,7 +92,8 @@ namespace com.alibaba.china.openapi.client.example.param.apiexample
* <pre></pre> * <pre></pre>
* *
*/ */
public void setRooms(int rooms) { public void setRooms(int rooms)
{
this.rooms = rooms; this.rooms = rooms;
} }

2
BBWY.1688SDK/serialize/Json2Deserializer.cs

@ -38,7 +38,7 @@ namespace com.alibaba.openapi.client.serialize
{ {
istream.Position = 0; //istream.Position = 0;
DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(ErrorExceptionDesc)); DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(ErrorExceptionDesc));
object resultObj = jsonSerializer.ReadObject(istream); object resultObj = jsonSerializer.ReadObject(istream);
ErrorExceptionDesc result = (ErrorExceptionDesc)resultObj; ErrorExceptionDesc result = (ErrorExceptionDesc)resultObj;

27
BBWY.1688SDK/serialize/Param2RequestSerializer.cs

@ -1,6 +1,7 @@
using com.alibaba.openapi.client.policy; using com.alibaba.openapi.client.policy;
using com.alibaba.openapi.client.primitive; using com.alibaba.openapi.client.primitive;
using com.alibaba.openapi.client.util; using com.alibaba.openapi.client.util;
using Newtonsoft.Json;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
@ -23,8 +24,9 @@ namespace com.alibaba.openapi.client.serialize
public Dictionary<String, Object> serialize(Object serializer) public Dictionary<String, Object> serialize(Object serializer)
{ {
Dictionary<String, Object> result = serializeNest(serializer); //Dictionary<String, Object> result = serializeNest(serializer);
return result; //return result;
return serializeParam(serializer);
} }
private Dictionary<String, Object> serializeNest(Object serializer) private Dictionary<String, Object> serializeNest(Object serializer)
@ -105,5 +107,26 @@ namespace com.alibaba.openapi.client.serialize
return result; return result;
} }
private Dictionary<string, object> serializeParam(object param)
{
Dictionary<string, object> result = new Dictionary<string, object>();
Type type = param.GetType();
var properties = type.GetProperties();
foreach (var property in properties)
{
var value = property.GetValue(param);
var valueType = value.GetType();
if (valueType.IsClass)
{
result.Add(property.Name, JsonConvert.SerializeObject(value));
}
else
{
result.Add(property.Name, value);
}
}
return result;
}
} }
} }

Loading…
Cancel
Save