# \[8.1.25\] Authentication Challenge payload changes java.util.date into unicode

**URL:** <https://forum.inductiveautomation.com/t/8-1-25-authentication-challenge-payload-changes-java-util-date-into-unicode/88313>\
**Category:** Ignition\
**Tags:** ignition81, perspective, scripting\
**Created:** [April 3, 2024, 10:02pm UTC](https://forum.inductiveautomation.com/t/8-1-25-authentication-challenge-payload-changes-java-util-date-into-unicode/88313 "2024-04-03T22:02:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [April 3, 2024, 10:02pm UTC](https://forum.inductiveautomation.com/t/8-1-25-authentication-challenge-payload-changes-java-util-date-into-unicode/88313/1 "2024-04-03T22:02:55Z")

</div>

When passing a java.util.date type object through an authentication challenge payload, the object is changed into a unicode object before being handed off to the authentication challenge complete handler.

To test this I made a button on my main view with the following script:

```auto
	logger = system.util.getLogger("ButtonScript")
	payload = {
		"identifier": "DateTest",
		"date": system.date.now()
	}
	
	logger.info(str(type(payload['date'])))
	system.perspective.authenticationChallenge(payload=payload, framing="embedded")

```

My authentication challenge complete handler has the following code:

```auto
logger = system.util.getLogger("AuthChallenge")
sourceType = payload.get("identifier", None)
if sourceType == "DateTest":
	logger.info(str(type(payload['date'])))

```

Looking at my logs, the 'date' member starts as a java.util.date object, but once received in the challenge complete handler, the 'date' member is now a unicode object.

![AuthPayload](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/b/2b95d061d60069655b7384549066e387f285407a.png)

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [April 3, 2024, 10:08pm UTC](https://forum.inductiveautomation.com/t/8-1-25-authentication-challenge-payload-changes-java-util-date-into-unicode/88313/2 "2024-04-03T22:08:38Z")

</div>

JSON doesn't know anything about dates.

There's a good flowchart of JSON construction here:  
[https://www.json.org/json-en.html](https://www.json.org/json-en.html)

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [April 3, 2024, 10:09pm UTC](https://forum.inductiveautomation.com/t/8-1-25-authentication-challenge-payload-changes-java-util-date-into-unicode/88313/3 "2024-04-03T22:09:46Z")

</div>

Yes?

As mentioned in the docs, the payload must be JSON-encodable. JSON doesn't have a 'real' date type - only strings, numbers, booleans, and null. So if you want a lossless datetime you can "rehydrate" into a real Date object on the other side, send your payload as `system.date.now().time` (or `system.date.toMillis(system.date.now())` and then use `system.date.fromMillis` on the other side.

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [April 3, 2024, 10:12pm UTC](https://forum.inductiveautomation.com/t/8-1-25-authentication-challenge-payload-changes-java-util-date-into-unicode/88313/4 "2024-04-03T22:12:12Z")

</div>

> [@Transistor](#):
>
> JSON doesn't know anything about dates.

Was not aware of this, I've only ever passed strings/ints through payloads.

For some reason I thought that Ignition did a smart conversion when handling the payload. Don't know why. 🙃

Guess this means I need to make a method to crawl my payload and convert all the dates to long ints

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [April 3, 2024, 10:14pm UTC](https://forum.inductiveautomation.com/t/8-1-25-authentication-challenge-payload-changes-java-util-date-into-unicode/88313/5 "2024-04-03T22:14:28Z")

</div>

I'd go with Paul's toMillis suggestion. The conversion back to datetime is simple and foolproof. Avoid working with dates as strings other than to convert them at the last possible moment for human consumption.

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [April 3, 2024, 10:27pm UTC](https://forum.inductiveautomation.com/t/8-1-25-authentication-challenge-payload-changes-java-util-date-into-unicode/88313/6 "2024-04-03T22:27:14Z")

</div>

I always use the base date objects, in this case I was running into the problem of unknowingly passing a query a string instead of a date. I rely on the components to do the stringify.
