# Creating a custom example json encoding for a newtype around string

**URL:** <https://softwaremill.community/t/creating-a-custom-example-json-encoding-for-a-newtype-around-string/227>\
**Category:** tapir\
**Created:** [June 13, 2023, 11:29am UTC](https://softwaremill.community/t/creating-a-custom-example-json-encoding-for-a-newtype-around-string/227 "2023-06-13T11:29:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![busti](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/busti/32/152_2.png) [@busti](https://softwaremill.community/u/busti)\
**Post date:** [June 13, 2023, 11:29am UTC](https://softwaremill.community/t/creating-a-custom-example-json-encoding-for-a-newtype-around-string/227/1 "2023-06-13T11:29:11Z")

</div>

We use `@newtype case class UserName(name: String)` for explicitly typing simple types a lot in our application.  
When creating tapir endpoints that use these types, the example json that is generated for these types is just the name followed by the wrapped type `{ "username": "string" }`.  
At the moment we are creating custom examples for some endpoints of our api using `jsonBody[SomeComplexType].example(Vector(???))`, but that is quite tedious since the entire example needs to be described for each endpoint.

Is it possible to create an example for all usages of this type instead, so that they apply to all endpoints where that type is used?

---

<div class="post-metadata">

**Author:** ![adamw](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/adamw/32/28_2.png) [@adamw](https://softwaremill.community/u/adamw)\
**Post date:** [June 13, 2023, 8:30pm UTC](https://softwaremill.community/t/creating-a-custom-example-json-encoding-for-a-newtype-around-string/227/2 "2023-06-13T20:30:26Z")

</div>

I’m not sure I understand the question. Would you like to auto-generate examples for the `SomeComplexType` type?
