如何覆盖 openedge 中的 toString 方法?
how can I override the toString method in openedge?
我有一个可序列化的 class,我想在序列化为 JSON 时提供我自己的 toString。
DEFINE PUBLIC PROPERTY address1 AS CHARACTER NO-UNDO
GET.
SET.
METHOD PUBLIC OVERRIDE CHARACTER toString( ):
DEFINE VARIABLE result AS CHARACTER NO-UNDO.
RETURN address1 + address2 + city + country.
END METHOD.
END CLASS. ```
I am also assigning the class to a temptable and using the write-json method of a dataset to output but I get the standard toString representation .."myClass": {
"prods:objId": 1,
"myClass": {
"address1": "xxxxx"
}
}
can I somehow override the toString being used ?
JsonSerializer
不使用 ToString()
,也不会让您对生成的格式有任何控制。 Serialize
method describes what data is written. If you want this ability added into the ABL, you can add an "Idea" at https://openedge.ideas.aha.io/ideas; OE 产品管理定期审查这些想法。
如果你今天想控制所写的内容,你需要自己动手。例如,OE 有 IJsonSerializer
interface, which allows types to declare that they can be serialised using the JsonSerializer
class.
我有一个可序列化的 class,我想在序列化为 JSON 时提供我自己的 toString。
DEFINE PUBLIC PROPERTY address1 AS CHARACTER NO-UNDO
GET.
SET.
METHOD PUBLIC OVERRIDE CHARACTER toString( ):
DEFINE VARIABLE result AS CHARACTER NO-UNDO.
RETURN address1 + address2 + city + country.
END METHOD.
END CLASS. ```
I am also assigning the class to a temptable and using the write-json method of a dataset to output but I get the standard toString representation .."myClass": {
"prods:objId": 1,
"myClass": {
"address1": "xxxxx"
}
}
can I somehow override the toString being used ?
JsonSerializer
不使用 ToString()
,也不会让您对生成的格式有任何控制。 Serialize
method describes what data is written. If you want this ability added into the ABL, you can add an "Idea" at https://openedge.ideas.aha.io/ideas; OE 产品管理定期审查这些想法。
如果你今天想控制所写的内容,你需要自己动手。例如,OE 有 IJsonSerializer
interface, which allows types to declare that they can be serialised using the JsonSerializer
class.