Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converter configure #23

Open
mobilemindtec opened this issue Aug 4, 2023 · 2 comments
Open

Converter configure #23

mobilemindtec opened this issue Aug 4, 2023 · 2 comments

Comments

@mobilemindtec
Copy link

Is there a possibility to configure the conversion? Like snake case, or custom field names.

@AugustNagro
Copy link
Member

AugustNagro commented Aug 6, 2023 via email

@mobilemindtec
Copy link
Author

mobilemindtec commented Jan 16, 2024

Hi,

have some ideas that are basic for a json converter lib:

1 - Annotation to declare the field name
2 - Option to ignore a field
3 - Option to omit null values
4 - Type of field for coercion or parse/format.

I made a change on my fork for native-converter with these features, except ignore null:

enum JsonType:
  case JsonIntStr
  case JsonNumStr
  case JsonBoolStr
  case JsonDate(pattern: String)(using val dateConverter: JsonDateConverter)
  case JsonAuto

case class Json(name: String = "",
                ignore: Boolean = false,
                omitNull: Boolean = false,
                // force type coerce
                typ: JsonType = JsonType.JsonAuto) extends StaticAnnotation

trait JsonDateConverter:
  def parse(date: String, pattern: String): js.Date
  def format(date: js.Date, pattern: String): String

I can share the code so you can take a look. I'm not an expert in scala.

See on master...mobilemindtec:native-converter:master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants