Effect CommunityEC
Effect Community3y ago
21 replies
kayng84

Using Schema for Message Encoding/Decoding with Different Naming Conventions

hello, I use Schema to encode/decode the message from/to my app with another system, the other system use snake_case for field name, my app for naming convention the field will be camelCase, I have declare my field almost same with the message will be encode/decode, just difference in field name
const CallMessage = S.struct({
  actionType: S.string,
  action: S.string
})
export type CallMessage = S.To<typeof CallMessage>
export const parseCallMessage = S.parse(CallMessage)
export const encodeCallMessage = S.encode(CallMessage)


Any way that I encode/decode directly from/to the message with format:
{
  "action_type": "hello",
  "action": "world"
}


Greatly appreciate for any help!
Was this page helpful?