-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WINDUPRULE-934 Added CDI Jakarta technology-tag (#855)
(cherry picked from commit dfbbaf8)
- Loading branch information
Showing
5 changed files
with
113 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
rules/rules-reviewed/technology-usage/tests/data/javaee/JsonControllerJakarta.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2015, Red Hat, Inc. and/or its affiliates, and individual | ||
* contributors by the @authors tag. See the copyright.txt in the | ||
* distribution for a full listing of individual contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
//package org.jboss.as.quickstarts.jsonp; | ||
|
||
import java.io.StringReader; | ||
|
||
import jakarta.enterprise.inject.Model; | ||
import jakarta.faces.application.FacesMessage; | ||
import jakarta.faces.context.FacesContext; | ||
import jakarta.inject.Inject; | ||
import jakarta.json.Json; | ||
import jakarta.json.JsonException; | ||
import jakarta.json.stream.JsonParser; | ||
import jakarta.json.stream.JsonParser.Event; | ||
|
||
@Model | ||
public class JsonControllerJakarta { | ||
|
||
@Inject | ||
private Person person; | ||
|
||
private String jsonString; | ||
|
||
private String parsedResult; | ||
|
||
public void generateJson() { | ||
jsonString = Json.createObjectBuilder() | ||
.add("name", person.getName()) | ||
.add("age", person.getAge()) | ||
.add("enabled", person.getEnabled()) | ||
.add("phones", Json.createArrayBuilder() | ||
.add(person.getPhone1()) | ||
.add(person.getPhone2()) | ||
) | ||
.add("addrees", Json.createObjectBuilder() | ||
.add("street", person.getAddressStreet()) | ||
.add("apt", person.getAddressApt()) | ||
.add("city", person.getAddressCity()) | ||
.add("zip", person.getAddressZip()) | ||
) | ||
.build().toString(); | ||
} | ||
|
||
public void parseJsonStream() { | ||
StringBuilder sb = new StringBuilder(); | ||
String json = getJsonString(); | ||
try { | ||
JsonParser parser = Json.createParser(new StringReader(json)); | ||
while (parser.hasNext()) { | ||
Event event = parser.next(); | ||
if (event.equals(Event.KEY_NAME)) { | ||
sb.append(" - - - - > Key: " + parser.getString() + " < - - - - - \n"); | ||
} | ||
if (event.equals(Event.VALUE_STRING)) { | ||
sb.append("Value as String: " + parser.getString() + "\n"); | ||
} | ||
if (event.equals(Event.VALUE_NUMBER)) { | ||
sb.append("Value as Number: " + parser.getInt() + "\n"); | ||
} | ||
if (event.equals(Event.VALUE_TRUE)) { | ||
sb.append("Value as Boolean: true\n"); | ||
} | ||
if (event.equals(Event.VALUE_FALSE)) { | ||
sb.append("Value as Boolean: false \n"); | ||
} | ||
} | ||
} catch (JsonException e) { | ||
FacesContext.getCurrentInstance().addMessage("form:parsed", new FacesMessage(e.getMessage())); | ||
} | ||
parsedResult = sb.toString(); | ||
} | ||
|
||
public void setJsonString(String jsonString) { | ||
this.jsonString = jsonString; | ||
} | ||
|
||
public String getJsonString() { | ||
return jsonString; | ||
} | ||
|
||
public String getParsedResult() { | ||
return parsedResult; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters