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

How to set the default time format for serialization of MVC response objects? #2454

Open
anden007 opened this issue May 6, 2024 · 2 comments

Comments

@anden007
Copy link

anden007 commented May 6, 2024

How should I set up MVC What is the format of the date and time when serializing objects in Response?
`
func (this *BussApiController) GetActivityBySearch() mvc.Result {

  ActivityList,total := loadFromDB(...)
  return mvc.Response{
        Object: iris.Map{"success": success, "message": message, "activityList": ActivityList, "total": total},
  }

}
`
I used to be able to set the default time format for JSON serialization using the GitHub. com/liamylian/jsontime/v2/v2 package when using v12.2.8. However, after upgrading to v12.2.11, this method has become ineffective.

`import(

  ...
  jsonTime "github.com/liamylian/jsontime/v2/v2"

)
func main() {

  jsonTime.SetDefaultTimeFormat("2006-01-02 15:04:05", time.Local)
  ...

}
`

@anden007
Copy link
Author

anden007 commented May 6, 2024

I seted app.Run(...,iris.WithTimeFormat("2006-01-02 15:04:05")) but it's not work.

@anden007 anden007 closed this as completed May 6, 2024
@anden007 anden007 reopened this May 6, 2024
@anden007
Copy link
Author

anden007 commented May 6, 2024

image
I have found the reason. The default serialization function now uses the encoding/JSON package, which used to be a JSONiter. This can explain why I am unable to use the jsonTime ' Set Default Time Format ("2006-01-02 15:04:05", time. Local) to set the default time format.

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

1 participant