Skip to content

Commit ba051e7

Browse files
committed
- Fix serialization of BusinessComponents for API object to be consistent with SDTs.
The old format ( key + description ) is only for Dataproviders and Procedures.
1 parent e79cc87 commit ba051e7

File tree

5 files changed

+17
-16
lines changed

5 files changed

+17
-16
lines changed

dotnet/src/dotnetcore/GxClasses.Web/Middleware/GXBCRestService.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ public override Task Post()
4343
bool gxinsertorupdate = IsRestParameter(INSERT_OR_UPDATE_PARAMETER);
4444

4545
GxSilentTrnSdt entity = (GxSilentTrnSdt)Activator.CreateInstance(_worker.GetType(), new Object[] { _gxContext });
46-
var entity_interface = MakeRestType(entity);
46+
var entity_interface = MakeRestType(entity, false);
4747
entity_interface = ReadRequestBodySDTObj(entity_interface.GetType());
4848

49-
var worker_interface = MakeRestType(_worker);
49+
var worker_interface = MakeRestType(_worker, false);
5050

5151
worker_interface.GetType().GetMethod("CopyFrom").Invoke(worker_interface, new object[] { entity_interface });
5252
if (gxcheck)
@@ -72,7 +72,7 @@ public override Task Post()
7272
SetStatusCode(HttpStatusCode.Created);
7373
}
7474
SetMessages(_worker.trn.GetMessages());
75-
return Serialize(MakeRestType(_worker));
75+
return Serialize(MakeRestType(_worker, false));
7676
}
7777
else
7878
{
@@ -119,7 +119,7 @@ public override Task Get(object parameters)
119119
if (_worker.Success())
120120
{
121121
SetMessages(_worker.trn.GetMessages());
122-
return Serialize(MakeRestType(_worker));
122+
return Serialize(MakeRestType(_worker, false));
123123
}
124124
else
125125
{
@@ -157,7 +157,7 @@ public override Task Delete(object parameters)
157157
{
158158
_worker.trn.context.CommitDataStores();
159159
SetMessages(_worker.trn.GetMessages());
160-
return Serialize(MakeRestType(_worker));
160+
return Serialize(MakeRestType(_worker, false));
161161
}
162162
else
163163
{
@@ -191,12 +191,12 @@ public override Task Put(object parameters)
191191
{
192192
bool gxcheck = IsRestParameter(CHECK_PARAMETER);
193193
GxSilentTrnSdt entity = (GxSilentTrnSdt)Activator.CreateInstance(_worker.GetType(), new Object[] { _gxContext });
194-
var entity_interface = MakeRestType(entity);
194+
var entity_interface = MakeRestType(entity, false);
195195
entity_interface = ReadRequestBodySDTObj(entity_interface.GetType());
196196
string entityHash = entity_interface.GetType().GetProperty("Hash").GetValue(entity_interface) as string;
197197

198198
ReflectionHelper.CallBCMethod(_worker, LOAD_METHOD, key);
199-
var worker_interface = MakeRestType(_worker);
199+
var worker_interface = MakeRestType(_worker, false);
200200
string currentHash = worker_interface.GetType().GetProperty("Hash").GetValue(worker_interface) as string;
201201
if (entityHash == currentHash)
202202
{

dotnet/src/dotnetframework/GxClasses/Core/Web/GxHttpServer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ private string GetStringFromStream(Stream stream)
396396
public override string ToString()
397397
{
398398
if (_httpReq == null)
399-
return String.Empty;
399+
return string.Empty;
400400
#if NETCORE
401401
return _httpReq.GetRawBodyString();
402402
#else

dotnet/src/dotnetframework/GxClasses/Domain/GxHttpClient.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,6 +1241,7 @@ private void WebExecute(string method, string name)
12411241
_statusCode = (short)resp.StatusCode;
12421242
_statusDescription = resp.StatusDescription;
12431243
resp.Close();
1244+
12441245
GXLogging.DebugSanitized(log, "_responseString " + ToString());
12451246
}
12461247
ClearSendStream();

dotnet/src/dotnetframework/GxClasses/Helpers/GXRestAPIClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,9 @@ public string GetJsonStr(string varName)
258258
else if (_responseData.Count >= 1 && !_responseData.ContainsKey(varName.ToLower()))
259259
{
260260
#if NETCORE
261-
sdt.FromJSonString(JsonSerializer.Serialize(_responseData), null);
261+
sdt.FromJSonString("{" + varName + ":" + JsonSerializer.Serialize(_responseData) + "}", null);
262262
#else
263-
sdt.FromJSonString(JSONHelper.Serialize(_responseData), null);
263+
sdt.FromJSonString("{" + varName + ":" + JSONHelper.Serialize(_responseData) + "}", null);
264264
#endif
265265
}
266266
return sdt;

dotnet/src/dotnetframework/GxClasses/Services/GxRestWrapper.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public virtual Task MethodBodyExecute(object key)
141141
Dictionary<string, string> formatParameters = ReflectionHelper.ParametersFormat(_procWorker, innerMethod);
142142
setWorkerStatus(_procWorker);
143143
_procWorker.cleanup();
144-
RestProcess(outputParameters);
144+
RestProcess(_procWorker, outputParameters);
145145
wrapped = GetWrappedStatus(_procWorker, wrapped, outputParameters, outputParameters.Count);
146146
ServiceHeaders();
147147
return Serialize(outputParameters, formatParameters, wrapped);
@@ -329,7 +329,7 @@ public virtual Task MethodUrlExecute(object key)
329329
int parCount = outputParameters.Count;
330330
setWorkerStatus(_procWorker);
331331
_procWorker.cleanup();
332-
RestProcess(outputParameters);
332+
RestProcess(_procWorker, outputParameters);
333333
bool wrapped = false;
334334
wrapped = GetWrappedStatus(_procWorker, wrapped, outputParameters, parCount);
335335
ServiceHeaders();
@@ -799,7 +799,7 @@ protected void Deserialize(string value, ref GxSilentTrnSdt sdt)
799799
sdt.FromJSonString(value);
800800
}
801801

802-
private static void RestProcess(Dictionary<string, object> outputParameters)
802+
private static void RestProcess(GXBaseObject worker, Dictionary<string, object> outputParameters)
803803
{
804804
foreach (string k in outputParameters.Keys.ToList())
805805
{
@@ -810,7 +810,7 @@ private static void RestProcess(Dictionary<string, object> outputParameters)
810810
}
811811
else
812812
{
813-
object o = MakeRestType(outputParameters[k]);
813+
object o = MakeRestType(outputParameters[k], worker.IsApiObject);
814814
if (p !=null && p.SdtSerializeAsNull())
815815
{
816816
outputParameters[k] = JNull.Value;
@@ -826,15 +826,15 @@ private static void RestProcess(Dictionary<string, object> outputParameters)
826826
}
827827
}
828828

829-
protected static object MakeRestType(object v)
829+
protected static object MakeRestType( object v, bool isApiObject)
830830
{
831831
Type vType = v.GetType();
832832
Type itemType;
833833
if (vType.IsConstructedGenericType && typeof(IGxCollection).IsAssignableFrom(vType))
834834
{
835835
Type restItemType=null;
836836
itemType = v.GetType().GetGenericArguments()[0];
837-
if (typeof(IGXBCCollection).IsAssignableFrom(vType))//Collection<BCType> convert to GxGenericCollection<BCType_RESTLInterface>
837+
if ((typeof(IGXBCCollection).IsAssignableFrom(vType)) && !isApiObject)//Collection<BCType> convert to GxGenericCollection<BCType_RESTLInterface>
838838
{
839839
restItemType = ClassLoader.FindType(Config.CommonAssemblyName, itemType.FullName + "_RESTLInterface", null);
840840
}

0 commit comments

Comments
 (0)