Skip to content

Commit

Permalink
fix/re-add proper Boolean json serialization.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpe42 committed Sep 20, 2023
1 parent fc148b4 commit 7bb91ee
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 24 deletions.
47 changes: 29 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,58 @@
# PagerDuty Event Client

This client aims to be compliant with the latest version of the [PagerDuty Event API](https://v2.developer.pagerduty.com/docs/events-api-v2), currently V2.
This client aims to be compliant with the latest version of
the [PagerDuty Event API](https://v2.developer.pagerduty.com/docs/events-api-v2), currently V2. It also only aims to be
supported against the latest GA OpenJDK release.

## Hello Event Trigger

```java
var client = PagerDutyEventClient.build()
var client=PagerDutyEventClient.build()
.defaultClientName("CLIENT_NAME")
.defaultRoutingKey("INTEGRATION_KEY")
.authToken("AUTH_TOKEN")
.create();

var payload = PagerDutyEventPayload.build()
var payload=PagerDutyEventPayload.build()
.summary("summary")
.source("source")
.severity(PagerDutySeverity.critical)
.timestamp(ZonedDateTime.now(UTC))
.component("component")
.group("group")
.type("class")
.customDetails("num-metric", 1)
.customDetails("string-metric", "val")
.customDetails("num-metric",1)
.customDetails("string-metric","val")
.link(PagerDutyLinkRef.build()
.href("https://github.com/comodal/pagerduty-client")
.text("Github pagerduty-client")
.create())
.href("https://github.com/comodal/pagerduty-client")
.text("Github pagerduty-client")
.create())
.image(PagerDutyImageRef.build()
.src("https://www.pagerduty.com/wp-content/uploads/2016/05/pagerduty-logo-green.png")
.href("https://www.pagerduty.com/")
.alt("pagerduty")
.create())
.src("https://www.pagerduty.com/wp-content/uploads/2016/05/pagerduty-logo-green.png")
.href("https://www.pagerduty.com/")
.alt("pagerduty")
.create())
.create();

var triggerResponse = client.triggerDefaultRouteEvent(payload).join();
System.out.println(triggerResponse);
var triggerResponse=client.triggerDefaultRouteEvent(payload).join();
System.out.println(triggerResponse);

var resolveResponse = client.resolveEvent(triggerResponse.getDedupeKey()).join();
System.out.println(resolveResponse);
var resolveResponse=client.resolveEvent(triggerResponse.getDedupeKey()).join();
System.out.println(resolveResponse);
```

## Library Layout
## Library Layout

The core module [systems.comodal.pagerduty_event_client](systems.comodal.pagerduty_event_client/src/main/java/module-info.java) has direct dependencies on `java.base`, `java.net.http` and a [PagerDutyEventAdapterFactory](systems.comodal.pagerduty_event_client/src/main/java/systems/comodal/pagerduty/event/data/adapters/PagerDutyEventAdapterFactory.java). The module [systems.comodal.pagerduty_event_json_iterator_adapter](systems.comodal.pagerduty_event_json_iterator_adapter/src/main/java/module-info.java) provides this factory and has a dependency on [systems.comodal.json_iterator](https://github.com/comodal/json-iterator). This separation is intended to make it easy to provide your own json parser if desired.
The core
module [systems.comodal.pagerduty_event_client](systems.comodal.pagerduty_event_client/src/main/java/module-info.java)
has direct dependencies on `java.base`, `java.net.http` and
a [PagerDutyEventAdapterFactory](systems.comodal.pagerduty_event_client/src/main/java/systems/comodal/pagerduty/event/data/adapters/PagerDutyEventAdapterFactory.java).

The [systems.comodal.pagerduty_event_json_iterator_adapter](systems.comodal.pagerduty_event_json_iterator_adapter/src/main/java/module-info.java)
module provides this factory and has a dependency
on [systems.comodal.json_iterator](https://github.com/comodal/json-iterator).
This separation is intended to make it easy for you to provide your own json parser (dependency) if desired. If not,
just use it, it is minimal and has no further transitive dependencies.

```bash
> ./gradlew pagerduty-event-json-iterator-adapter:dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,12 +295,17 @@ private static String toJson(final Map<String, Object> object) {
final var key = entry.getKey();
final var val = entry.getValue();
return switch (val) {
case BigDecimal num -> String.format("""
"%s":"%s\"""", key, num.toPlainString());
case BigInteger num -> String.format("""
"%s":"%s\"""", key, num);
case Number num -> String.format("""
"%s":%s""", key, num);
case null -> String.format("""
"%s":null""", key);
case BigDecimal bigDecimal -> String.format("""
"%s":"%s\"""", key, bigDecimal.toPlainString());
case BigInteger bigInteger -> String.format("""
"%s":"%s\"""", key, bigInteger);
case Number number -> String.format("""
"%s":%s""", key, number);
case Boolean bool -> String.format("""
"%s":%s""", key, bool);
//noinspection DataFlowIssue
case Object obj -> {
final var str = obj.toString();
yield String.format("""
Expand Down

0 comments on commit 7bb91ee

Please sign in to comment.