问:
Matching Roman Numbers
I have regular expression

```<code>(IX|IV|V?I{0,3}|M{1,4}|CM|CD|D?C{1,3}|XC|XL|L?X{1,3})
</code>```

I use it to detect if there is any roman number in text.

```<code>eregi("( IX|IV|V?I{0,3}[\.]| M{1,4}[\.]| CM|CD|D?C{1,3}[\.]| XC|XL|L?X{1,3}[\.])", $title, $regs)
</code>```

But format of roman number is always like this: " IV."... I have added in eregi example white space before number and "." after number but I still get the same result. If text is something like "somethinvianyyhing" the result will be vi (between both)...

What am I doing wrong?

答:
You have no space before VI the space belongs always to the alternative before it was written and not to all. The same for the \. it belongs always to the alternative where it was written.

Try this

```<code>" (IX|IV|V?I{0,3}|M{1,4}|CM|CD|D?C{1,3}|XC|XL|L?X{1,3})\."
</code>```

See it here on Regexr

This will match

I.

 II.

 III.

 IV.

 V.

 VI.

 VII.

 VIII.

 IX.

 X.

But not

XI.
 MMI.
 MMXI.

somethinvianyyhing

Your approach to match roman numbers is far from being correct, an approach to match the roman numbers more correct is this, for numbers till 50 (L)

```<code>^(?:XL|L|L?(?:IX|X{1,3}|X{0,3}(?:IX|IV|V|V?I{1,3})))$
</code>```

See it here on Regexr

I tested this only on the surface, but you see this will really get complex and in this expression C, D and M are still missing.

Not to speak about special cases for example 4 = IV = IIII and there are more of them.

Wikipedia about Roman numbers

Title: Matching Roman Numbers

Body:
I have regular expression

(IX|IV|V?I{0,3}|M{1,4}|CM|CD|D?C{1,3}|XC|XL|L?X{1,3})

I use it to detect if there is any roman number in text.

eregi("( IX|IV|V?I{0,3}[\.]| M{1,4}[\.]| CM|CD|D?C{1,3}[\.]| XC|XL|L?X{1,3}[\.])", $title, $regs)

But format of roman number is always like this: " IV."... I have added in eregi example white space before number and "." after number but I still get the same result. If text is something like "somethinvianyyhing" the result will be vi (between both)...

What am I doing wrong?

Body:
You have no space before VI the space belongs always to the alternative before it was written and not to all. The same for the \. it belongs always to the alternative where it was written.

Try this

" (IX|IV|V?I{0,3}|M{1,4}|CM|CD|D?C{1,3}|XC|XL|L?X{1,3})\."

See it here on Regexr

This will match

I.

 II.

 III.

 IV.

 V.

 VI.

 VII.

 VIII.

 IX.

 X.

But not

XI.
 MMI.
 MMXI.

somethinvianyyhing

Your approach to match roman numbers is far from being correct, an approach to match the roman numbers more correct is this, for numbers till 50 (L)

^(?:XL|L|L?(?:IX|X{1,3}|X{0,3}(?:IX|IV|V|V?I{1,3})))$

See it here on Regexr

I tested this only on the surface, but you see this will really get complex and in this expression C, D and M are still missing.

Not to speak about special cases for example 4 = IV = IIII and there are more of them.

Wikipedia about Roman numbers


来源: stackexchange

问:
Can someone help to turn this sidebar into hamburger base on ratio?
Hey i new to this web code thing, and i need help from all of you.
I have side menu that i need to convert it to hamburger menu when the screen is small mobile sized.

I need all of this content
 to be hamburger menu on mobile scale ratio

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
}

.sidebar {
  height: 300px;
  width: 180px;
  position: fixed;
  top: 0;
  left: 10px;
  background-color: white;
  padding-top: 60px;
  margin-top: 200px;
  box-shadow: 4px 4px 4px rgba(0, 0, 0, 0.25);
  border-radius: 20px;
}

.sidebar a {
  padding: 8px 8px 8px 32px;
  text-decoration: none;
  font-size: 12px;
  color: #858585;
  display: block;
  margin-top: -10px;
  margin-left: -10px;
}

.sidebar a:hover {
  color: #0E73B9;
}

main .sidebar {
  position: absolute;
  top: 0;
  right: 100px;
  font-size: 36px;
  margin-left: 50px;
}

.material-icons,
.icon-text {
  vertical-align: middle;
}

.material-icons {
  margin-right: 30px
}

#main {
  transition: margin-left 0.5s;
  padding: 16px;
  margin-left: 250px;
}

@media screen and (max-height: 450px) {
  .sidebar {
    padding-top: 15px;
  }
  .sidebar a {
    font-size: 18px;
  }
}

.dropdown {
  position: block;
  display: inline-block;
  background-color: white;
}

.dropdown-content {
  display: none;
  position: absolute;
  background-color: white;
  min-width: 160px;
  /*box-shadow: 4px 4px 4px rgba(0, 0, 0, 0.25);*/
  border-radius: 20px;
  margin-left: 20px;
  text-align: center;
  height: 80px;
  margin-top: -30px;
}

.dropdown-content a {
  color: #858585;
  padding: 12px 16px;
  text-decoration: none;
  display: block;
  margin-top: 1px;
  background-color: white;
  margin-left: 5px;
}

.dropdown-content a:hover {
  background-color: #f1f1f1
}

.dropdown:hover .dropdown-content {
  display: block;
  background-color: white;
}

.dropdown:hover .down {
  background-color: white;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><!DOCTYPE html>
<html lang="en">

<head>

  <title>Test</title>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="style.css">
  <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">

</head>

<body>
  <div id="mySidebar" class="sidebar">
    <span><i class="material-icons">home</i><span class="icon-text">Dashboard</span><br>
    <div class="dropdown">
      <div class="down">
        <i class="material-icons">info</i><span class="icon-text"></span>Monitoring</span>
        </a><br>
      </div>
      <div class="dropdown-content">
        Reader
        RFID
      </div>
    </div>
    <i class="material-icons">settings</i><span class="icon-text"></span>Settings</span><br>
    <i class="material-icons">logout</i><span class="icon-text"></span>Logout<span>
  </div>

</body></code>```

答:
You can do something like this, I guess you can do further editing to match style that you use but most of the css you can re-use. If you check snippet from below in full screen and try to resize your browser you will see how your menu switch to hamburger menu when window size becomes less than 1000px

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
}

.sidebar {
  height: 300px;
  width: 180px;
  position: fixed;
  top: 0;
  left: 10px;
  background-color: white;
  padding-top: 60px;
  margin-top: 200px;
  box-shadow: 4px 4px 4px rgba(0, 0, 0, 0.25);
  border-radius: 20px;
}

.sidebar a {
  padding: 8px 8px 8px 32px;
  text-decoration: none;
  font-size: 12px;
  color: #858585;
  display: block;
  margin-top: -10px;
  margin-left: -10px;
}

.sidebar a:hover {
  color: #0E73B9;
}

main .sidebar {
  position: absolute;
  top: 0;
  right: 100px;
  font-size: 36px;
  margin-left: 50px;
}

.material-icons,
.icon-text {
  vertical-align: middle;
}

.material-icons {
  margin-right: 30px
}

#main {
  transition: margin-left 0.5s;
  padding: 16px;
  margin-left: 250px;
}

@media screen and (max-height: 450px) {
  .sidebar {
    padding-top: 15px;
  }
  .sidebar a {
    font-size: 18px;
  }
}

.dropdown {
  position: block;
  display: inline-block;
  background-color: white;
}

.dropdown-content {
  display: none;
  position: absolute;
  background-color: white;
  min-width: 160px;
  /*box-shadow: 4px 4px 4px rgba(0, 0, 0, 0.25);*/
  border-radius: 20px;
  margin-left: 20px;
  text-align: center;
  height: 80px;
  margin-top: -30px;
}

.dropdown-content a {
  color: #858585;
  padding: 12px 16px;
  text-decoration: none;
  display: block;
  margin-top: 1px;
  background-color: white;
  margin-left: 5px;
}

.dropdown-content a:hover {
  background-color: #f1f1f1
}

.dropdown:hover .dropdown-content {
  display: block;
  background-color: white;
}

.dropdown:hover .down {
  background-color: white;
}

#menuToggle {
  display: block;
  position: relative;
  top: 50px;
  left: 50px;
  z-index: 1;
  -webkit-user-select: none;
  user-select: none;
}

#menuToggle a {
  text-decoration: none;
  color: #232323;
  transition: color 0.3s ease;
}

#menuToggle a:hover {
  color: tomato;
}

#menuToggle input {
  display: block;
  width: 40px;
  height: 32px;
  position: absolute;
  top: -7px;
  left: -5px;
  cursor: pointer;
  opacity: 0;
  /* hide this */
  z-index: 2;
  /* and place it over the hamburger */
  -webkit-touch-callout: none;
}

/*
 * Just a quick hamburger
 */

#menuToggle span {
  display: block;
  width: 33px;
  height: 4px;
  margin-bottom: 5px;
  position: relative;
  background: #cdcdcd;
  border-radius: 3px;
  z-index: 1;
  transform-origin: 4px 0px;
  transition: transform 0.5s cubic-bezier(0.77, 0.2, 0.05, 1.0), background 0.5s cubic-bezier(0.77, 0.2, 0.05, 1.0), opacity 0.55s ease;
}

#menuToggle span:first-child {
  transform-origin: 0% 0%;
}

#menuToggle span:nth-last-child(2) {
  transform-origin: 0% 100%;
}

/*
 * Transform all the slices of hamburger
 * into a crossmark.
 */

#menuToggle input:checked~span {
  opacity: 1;
  transform: rotate(45deg) translate(-2px, -1px);
  background: #232323;
}

/*
 * But let's hide the middle one.
 */

#menuToggle input:checked~span:nth-last-child(3) {
  opacity: 0;
  transform: rotate(0deg) scale(0.2, 0.2);
}

/*
 * Ohyeah and the last one should go the other direction
 */

#menuToggle input:checked~span:nth-last-child(2) {
  transform: rotate(-45deg) translate(0, -1px);
}

/*
 * Make this absolute positioned
 * at the top left of the screen
 */

#menu {
  position: absolute;
  width: 300px;
  margin: -100px 0 0 -50px;
  padding: 50px;
  padding-top: 125px;
  background: #ededed;
  list-style-type: none;
  -webkit-font-smoothing: antialiased;
  /* to stop flickering of text in safari */
  transform-origin: 0% 0%;
  transform: translate(-100%, 0);
  transition: transform 0.5s cubic-bezier(0.77, 0.2, 0.05, 1.0);
}

#menu li {
  padding: 10px 0;
  font-size: 22px;
  display: flex;
  align-items: center;
}

nav {
  display: none;
}

/*
 * And let's slide it in from the left
 */

#menuToggle input:checked~ul {
  transform: none;
}

@media screen and (max-width: 1000px) {
  .sidebar {
    display: none;
  }
  nav {
    display: block;
  }
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><!DOCTYPE html>
<html lang="en">

<head>

  <title>Test</title>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="style.css">
  <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">

</head>

<body>
  <nav role="navigation">
    <div id="menuToggle">
      <!--
    A fake / hidden checkbox is used as click reciever,
    so you can use the :checked selector on it.
    -->
      <input type="checkbox" />

      <!--
    Some spans to act as a hamburger.

    They are acting like a real hamburger,
    not that McDonalds stuff.
    -->
      <span></span>
      <span></span>
      <span></span>

      <!--
    Too bad the menu has to be inside of the button
    but hey, it's pure CSS magic.
    -->
      <ul id="menu">

          <li><i class="material-icons">home</i>Dashboard</li>

          <li><i class="material-icons">info</i>Monitoring</li>

          <li><i class="material-icons">settings</i>Settings</li>

          <li><i class="material-icons">logout</i>Logout</li>

      </ul>
    </div>
  </nav>
  <div id="mySidebar" class="sidebar">
    <span><i class="material-icons">home</i><span class="icon-text">Dashboard</span><br>
    <div class="dropdown">
      <div class="down">
        <i class="material-icons">info</i><span class="icon-text"></span>Monitoring</span>
        </a><br>
      </div>
      <div class="dropdown-content">
        Reader
        RFID
      </div>
    </div>
    <i class="material-icons">settings</i><span class="icon-text"></span>Settings</span><br>
    <i class="material-icons">logout</i><span class="icon-text"></span>Logout<span>
  </div>

</body>

</html></code>```

ContentLicense: CC BY-SA 4.0

Body:
Hey i new to this web code thing, and i need help from all of you.
I have side menu that i need to convert it to hamburger menu when the screen is small mobile sized.

I need all of this content
 to be hamburger menu on mobile scale ratio

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
}

.sidebar {
  height: 300px;
  width: 180px;
  position: fixed;
  top: 0;
  left: 10px;
  background-color: white;
  padding-top: 60px;
  margin-top: 200px;
  box-shadow: 4px 4px 4px rgba(0, 0, 0, 0.25);
  border-radius: 20px;
}

.sidebar a {
  padding: 8px 8px 8px 32px;
  text-decoration: none;
  font-size: 12px;
  color: #858585;
  display: block;
  margin-top: -10px;
  margin-left: -10px;
}

.sidebar a:hover {
  color: #0E73B9;
}

main .sidebar {
  position: absolute;
  top: 0;
  right: 100px;
  font-size: 36px;
  margin-left: 50px;
}

.material-icons,
.icon-text {
  vertical-align: middle;
}

.material-icons {
  margin-right: 30px
}

#main {
  transition: margin-left 0.5s;
  padding: 16px;
  margin-left: 250px;
}

@media screen and (max-height: 450px) {
  .sidebar {
    padding-top: 15px;
  }
  .sidebar a {
    font-size: 18px;
  }
}

.dropdown {
  position: block;
  display: inline-block;
  background-color: white;
}

.dropdown-content {
  display: none;
  position: absolute;
  background-color: white;
  min-width: 160px;
  /*box-shadow: 4px 4px 4px rgba(0, 0, 0, 0.25);*/
  border-radius: 20px;
  margin-left: 20px;
  text-align: center;
  height: 80px;
  margin-top: -30px;
}

.dropdown-content a {
  color: #858585;
  padding: 12px 16px;
  text-decoration: none;
  display: block;
  margin-top: 1px;
  background-color: white;
  margin-left: 5px;
}

.dropdown-content a:hover {
  background-color: #f1f1f1
}

.dropdown:hover .dropdown-content {
  display: block;
  background-color: white;
}

.dropdown:hover .down {
  background-color: white;
}

<!DOCTYPE html>

  <title>Test</title>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="style.css">
  <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">

    homeDashboard

        infoMonitoring

        Reader
        RFID

    settingsSettings

    logoutLogout

Body:
You can do something like this, I guess you can do further editing to match style that you use but most of the css you can re-use. If you check snippet from below in full screen and try to resize your browser you will see how your menu switch to hamburger menu when window size becomes less than 1000px

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
}

.sidebar {
  height: 300px;
  width: 180px;
  position: fixed;
  top: 0;
  left: 10px;
  background-color: white;
  padding-top: 60px;
  margin-top: 200px;
  box-shadow: 4px 4px 4px rgba(0, 0, 0, 0.25);
  border-radius: 20px;
}

.sidebar a {
  padding: 8px 8px 8px 32px;
  text-decoration: none;
  font-size: 12px;
  color: #858585;
  display: block;
  margin-top: -10px;
  margin-left: -10px;
}

.sidebar a:hover {
  color: #0E73B9;
}

main .sidebar {
  position: absolute;
  top: 0;
  right: 100px;
  font-size: 36px;
  margin-left: 50px;
}

.material-icons,
.icon-text {
  vertical-align: middle;
}

.material-icons {
  margin-right: 30px
}

#main {
  transition: margin-left 0.5s;
  padding: 16px;
  margin-left: 250px;
}

@media screen and (max-height: 450px) {
  .sidebar {
    padding-top: 15px;
  }
  .sidebar a {
    font-size: 18px;
  }
}

.dropdown {
  position: block;
  display: inline-block;
  background-color: white;
}

.dropdown-content {
  display: none;
  position: absolute;
  background-color: white;
  min-width: 160px;
  /*box-shadow: 4px 4px 4px rgba(0, 0, 0, 0.25);*/
  border-radius: 20px;
  margin-left: 20px;
  text-align: center;
  height: 80px;
  margin-top: -30px;
}

.dropdown-content a {
  color: #858585;
  padding: 12px 16px;
  text-decoration: none;
  display: block;
  margin-top: 1px;
  background-color: white;
  margin-left: 5px;
}

.dropdown-content a:hover {
  background-color: #f1f1f1
}

.dropdown:hover .dropdown-content {
  display: block;
  background-color: white;
}

.dropdown:hover .down {
  background-color: white;
}

#menuToggle {
  display: block;
  position: relative;
  top: 50px;
  left: 50px;
  z-index: 1;
  -webkit-user-select: none;
  user-select: none;
}

#menuToggle a {
  text-decoration: none;
  color: #232323;
  transition: color 0.3s ease;
}

#menuToggle a:hover {
  color: tomato;
}

#menuToggle input {
  display: block;
  width: 40px;
  height: 32px;
  position: absolute;
  top: -7px;
  left: -5px;
  cursor: pointer;
  opacity: 0;
  /* hide this */
  z-index: 2;
  /* and place it over the hamburger */
  -webkit-touch-callout: none;
}

/*
 * Just a quick hamburger
 */

#menuToggle span {
  display: block;
  width: 33px;
  height: 4px;
  margin-bottom: 5px;
  position: relative;
  background: #cdcdcd;
  border-radius: 3px;
  z-index: 1;
  transform-origin: 4px 0px;
  transition: transform 0.5s cubic-bezier(0.77, 0.2, 0.05, 1.0), background 0.5s cubic-bezier(0.77, 0.2, 0.05, 1.0), opacity 0.55s ease;
}

#menuToggle span:first-child {
  transform-origin: 0% 0%;
}

#menuToggle span:nth-last-child(2) {
  transform-origin: 0% 100%;
}

/*
 * Transform all the slices of hamburger
 * into a crossmark.
 */

#menuToggle input:checked~span {
  opacity: 1;
  transform: rotate(45deg) translate(-2px, -1px);
  background: #232323;
}

/*
 * But let's hide the middle one.
 */

#menuToggle input:checked~span:nth-last-child(3) {
  opacity: 0;
  transform: rotate(0deg) scale(0.2, 0.2);
}

/*
 * Ohyeah and the last one should go the other direction
 */

#menuToggle input:checked~span:nth-last-child(2) {
  transform: rotate(-45deg) translate(0, -1px);
}

/*
 * Make this absolute positioned
 * at the top left of the screen
 */

#menu {
  position: absolute;
  width: 300px;
  margin: -100px 0 0 -50px;
  padding: 50px;
  padding-top: 125px;
  background: #ededed;
  list-style-type: none;
  -webkit-font-smoothing: antialiased;
  /* to stop flickering of text in safari */
  transform-origin: 0% 0%;
  transform: translate(-100%, 0);
  transition: transform 0.5s cubic-bezier(0.77, 0.2, 0.05, 1.0);
}

#menu li {
  padding: 10px 0;
  font-size: 22px;
  display: flex;
  align-items: center;
}

nav {
  display: none;
}

/*
 * And let's slide it in from the left
 */

#menuToggle input:checked~ul {
  transform: none;
}

@media screen and (max-width: 1000px) {
  .sidebar {
    display: none;
  }
  nav {
    display: block;
  }
}

<!DOCTYPE html>
<html lang="en">

<head>

  <title>Test</title>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="style.css">
  <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">

</head>

<body>
  <nav role="navigation">
    <div id="menuToggle">
      <!--
    A fake / hidden checkbox is used as click reciever,
    so you can use the :checked selector on it.
    -->
      <input type="checkbox" />

      <!--
    Some spans to act as a hamburger.

    They are acting like a real hamburger,
    not that McDonalds stuff.
    -->
      <span></span>
      <span></span>
      <span></span>

      <!--
    Too bad the menu has to be inside of the button
    but hey, it's pure CSS magic.
    -->
      <ul id="menu">
        <a href="#">
          <li><i class="material-icons">home</i>Dashboard</li>
        </a>
        <a href="#">
          <li><i class="material-icons">info</i>Monitoring</li>
        </a>
        <a href="#">
          <li><i class="material-icons">settings</i>Settings</li>
        </a>
        <a href="#">
          <li><i class="material-icons">logout</i>Logout</li>
        </a>
      </ul>
    </div>
  </nav>
  <div id="mySidebar" class="sidebar">
    <a href="#"><span><i class="material-icons">home</i><span class="icon-text">Dashboard</span></a><br>
    <div class="dropdown">
      <div class="down">
        <a href="#"><i class="material-icons">info</i><span class="icon-text"></span>Monitoring</a></span>
        </a><br>
      </div>
      <div class="dropdown-content">
        <a href="index.html">Reader</a>
        <a href="rfid.html">RFID</a>
      </div>
    </div>
    <a href="settingakun.html"><i class="material-icons">settings</i><span class="icon-text"></span>Settings</span></a><br>
    <a href="#"><i class="material-icons">logout</i><span class="icon-text"></span>Logout<span></a>
  </div>

</body>

</html>


问:
Rails 5 - save rolls back because nested models parent model is not being saved before child model
Ok folks, Rails 5 has really had its nuances differing from Rails 4. What I have going on is that every time I click the submit button on the form it reloads with the error Profile user must exist and Profile user can't be blank. The form loads fine including the nested models form, but for what ever reason it is failing to save the parent model before attempting to save the child model with the following output to the console:

```<code>Puma starting in single mode...
* Version 3.7.0 (ruby 2.2.6-p396), codename: Snowy Sagebrush
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://0.0.0.0:3000
Use Ctrl-C to stop
Started POST "/users" for 192.168.0.31 at 2017-03-09 18:51:04 -0500
Cannot render console from 192.168.0.31! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
  ActiveRecord::SchemaMigration Load (0.2ms)  SELECT `schema_migrations`.* FROM `schema_migrations`
Processing by UsersController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"JPKO+ppAYqwWS8tWeXhEtbUWynXREu9jYlF0KIlyPgUaabHSzjPZocSxCvr/WEm1r6wAQyT1CvA6hNkZWfPD3Q==", "user"=>{"username"=>"test", "password"=>"[FILTERED]", "user_type_id"=>"1", "profile_attributes"=>{"first_name"=>"123", "middle_name"=>"123", "last_name"=>"123", "email"=>"123@123.com", "phone_number"=>"1234567890", "cell_number"=>"1234567890"}}, "commit"=>"Create User"}
   (0.1ms)  BEGIN
   (0.2ms)  ROLLBACK
  Rendering users/new.html.erb within layouts/application
  Rendered users/_form.html.erb (112.5ms)
  Rendered users/new.html.erb within layouts/application (118.7ms)
Completed 200 OK in 834ms (Views: 780.1ms | ActiveRecord: 2.2ms)
</code>```

I have have had other problems out of this relationship and I am thinking that maybe I need to rebuild the project.
Here is all of the relevant code around this issue:

```<code>###############################################################################
### Users Model
###############################################################################
    class User < ApplicationRecord
      has_one :profile, inverse_of: :user
      accepts_nested_attributes_for :profile, allow_destroy: true
    end

###############################################################################
### Profile Model
###############################################################################
    class Profile < ApplicationRecord
      belongs_to :user, inverse_of: :profile
      validates_presence_of :user
    end
###############################################################################
### Users Controller
###############################################################################
    class UsersController < ApplicationController
      before_action :set_user, only: [:show, :edit, :update, :destroy]

      # GET /users
      # GET /users.json
      def index
        @users = User.all
      end

      # GET /users/1
      # GET /users/1.json
      def show
        @user.build_profile
      end

      # GET /users/new
      def new
        @user = User.new
        @user.build_profile
      end

      # GET /users/1/edit
      def edit
        @user.build_profile
      end

      # POST /users
      # POST /users.json
      def create
        @user = User.new(user_params)

        respond_to do |format|
          if @user.save
            format.html { redirect_to @user, notice: 'User was successfully created.' }
            format.json { render :show, status: :created, location: @user }
          else
            format.html { render :new }
            format.json { render json: @user.errors, status: :unprocessable_entity }
          end
        end
      end

      # PATCH/PUT /users/1
      # PATCH/PUT /users/1.json
      def update
        respond_to do |format|
          if @user.update(user_params)
            format.html { redirect_to @user, notice: 'User was successfully updated.' }
            format.json { render :show, status: :ok, location: @user }
          else
            format.html { render :edit }
            format.json { render json: @user.errors, status: :unprocessable_entity }
          end
        end
      end

      # DELETE /users/1
      # DELETE /users/1.json
      def destroy
        @user.destroy
        respond_to do |format|
          format.html { redirect_to users_url, notice: 'User was successfully destroyed.' }
          format.json { head :no_content }
        end
      end

      private
        # Use callbacks to share common setup or constraints between actions.
        def set_user
          @user = User.find(params[:id])
        end

        # Never trust parameters from the scary internet, only allow the white list through.
        def user_params
          params.require(:user).permit(:username, :password, :user_type_id, profile_attributes: [:id, :user_id, :first_name, :middle_name, :last_name, :phone_number, :cell_number, :email])
        end
    end

###############################################################################
### Form View
###############################################################################
    <%= form_for(@user) do |f| %>
      <% if user.errors.any? %>
        <div id="error_explanation">
          <h2><%= pluralize(user.errors.count, "error") %> prohibited this user from being saved:</h2>

          <ul>
          <% user.errors.full_messages.each do |message| %>
            <li><%= message %></li>
          <% end %>
            <!--<li><%= debug f %></li>-->
          </ul>
        </div>
      <% end %>

      <div class="field">
        <%= f.label :username %>
        <%= f.text_field :username %>
      </div>

      <div class="field">
        <%= f.label :password %>
        <%= f.text_field :password %>
      </div>

      <div class="field">
        <% if params[:trainer] == "true" %>
          <%= f.label :user_type_id %>
          <%= f.text_field :user_type_id, :readonly => true, :value => '2' %>
        <% else %>
          <%= f.label :user_type_id %>
          <%= f.text_field :user_type_id, :readonly => true, :value => '1'  %>
        <% end %>
      </div>
        <h2>Account Profile</h2>
        <%= f.fields_for :profile do |profile| %>
          <%#= profile.inspect %>
            <div>
              <%= profile.label :first_name %>
              <%= profile.text_field :first_name %>
            </div>
            <div>
              <%= profile.label :middle_name %>
              <%= profile.text_field :middle_name %>
            </div>
            <div>
              <%= profile.label :last_name %>
              <%= profile.text_field :last_name %>
            </div>
            <div>
              <%= profile.label :email %>
              <%= profile.text_field :email %>
            </div>
            <div>
              <%= profile.label :phone_number %>
              <%= profile.telephone_field :phone_number %>
            </div>
            <div>
              <%= profile.label :cell_phone %>
              <%= profile.telephone_field :cell_number %>
            </div>
        <% end %>
      <div class="actions">
        <%= f.submit %>
      </div>
        <%= debug params %>
        <%= debug user %>
        <%= debug user.profile %>
    <% end %>
</code>```

答:
I came across this question because I had the same problem but only for my rspec tests. I ended up doing rails db:reset RAILS_ENV=test and that solved it. I did not need to add inverse_of: :user or autosave:true to the models.

One theory you could check in a dev or production system is if your seed for the table somehow got off. So then it can't insert the user row because the id is in use and then the profile create fails because the user create failed. In postgresql you could run:  SELECT setval('users_id_seq', (SELECT max(id) FROM users}));

ContentLicense: CC BY-SA 3.0

Body:
Ok folks, Rails 5 has really had its nuances differing from Rails 4. What I have going on is that every time I click the submit button on the form it reloads with the error Profile user must exist and Profile user can't be blank. The form loads fine including the nested models form, but for what ever reason it is failing to save the parent model before attempting to save the child model with the following output to the console:

Puma starting in single mode...
* Version 3.7.0 (ruby 2.2.6-p396), codename: Snowy Sagebrush
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://0.0.0.0:3000
Use Ctrl-C to stop
Started POST "/users" for 192.168.0.31 at 2017-03-09 18:51:04 -0500
Cannot render console from 192.168.0.31! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
  ActiveRecord::SchemaMigration Load (0.2ms)  SELECT `schema_migrations`.* FROM `schema_migrations`
Processing by UsersController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"JPKO+ppAYqwWS8tWeXhEtbUWynXREu9jYlF0KIlyPgUaabHSzjPZocSxCvr/WEm1r6wAQyT1CvA6hNkZWfPD3Q==", "user"=>{"username"=>"test", "password"=>"[FILTERED]", "user_type_id"=>"1", "profile_attributes"=>{"first_name"=>"123", "middle_name"=>"123", "last_name"=>"123", "email"=>"123@123.com", "phone_number"=>"1234567890", "cell_number"=>"1234567890"}}, "commit"=>"Create User"}
   (0.1ms)  BEGIN
   (0.2ms)  ROLLBACK
  Rendering users/new.html.erb within layouts/application
  Rendered users/_form.html.erb (112.5ms)
  Rendered users/new.html.erb within layouts/application (118.7ms)
Completed 200 OK in 834ms (Views: 780.1ms | ActiveRecord: 2.2ms)

I have have had other problems out of this relationship and I am thinking that maybe I need to rebuild the project.
Here is all of the relevant code around this issue:

###############################################################################
### Users Model
###############################################################################
    class User < ApplicationRecord
      has_one :profile, inverse_of: :user
      accepts_nested_attributes_for :profile, allow_destroy: true
    end

###############################################################################
### Profile Model
###############################################################################
    class Profile < ApplicationRecord
      belongs_to :user, inverse_of: :profile
      validates_presence_of :user
    end
###############################################################################
### Users Controller
###############################################################################
    class UsersController < ApplicationController
      before_action :set_user, only: [:show, :edit, :update, :destroy]

      # GET /users
      # GET /users.json
      def index
        @users = User.all
      end

      # GET /users/1
      # GET /users/1.json
      def show
        @user.build_profile
      end

      # GET /users/new
      def new
        @user = User.new
        @user.build_profile
      end

      # GET /users/1/edit
      def edit
        @user.build_profile
      end

      # POST /users
      # POST /users.json
      def create
        @user = User.new(user_params)

        respond_to do |format|
          if @user.save
            format.html { redirect_to @user, notice: 'User was successfully created.' }
            format.json { render :show, status: :created, location: @user }
          else
            format.html { render :new }
            format.json { render json: @user.errors, status: :unprocessable_entity }
          end
        end
      end

      # PATCH/PUT /users/1
      # PATCH/PUT /users/1.json
      def update
        respond_to do |format|
          if @user.update(user_params)
            format.html { redirect_to @user, notice: 'User was successfully updated.' }
            format.json { render :show, status: :ok, location: @user }
          else
            format.html { render :edit }
            format.json { render json: @user.errors, status: :unprocessable_entity }
          end
        end
      end

      # DELETE /users/1
      # DELETE /users/1.json
      def destroy
        @user.destroy
        respond_to do |format|
          format.html { redirect_to users_url, notice: 'User was successfully destroyed.' }
          format.json { head :no_content }
        end
      end

      private
        # Use callbacks to share common setup or constraints between actions.
        def set_user
          @user = User.find(params[:id])
        end

        # Never trust parameters from the scary internet, only allow the white list through.
        def user_params
          params.require(:user).permit(:username, :password, :user_type_id, profile_attributes: [:id, :user_id, :first_name, :middle_name, :last_name, :phone_number, :cell_number, :email])
        end
    end

###############################################################################
### Form View
###############################################################################
    <%= form_for(@user) do |f| %>
      <% if user.errors.any? %>

<%= pluralize(user.errors.count, "error") %> prohibited this user from being saved:

          <% user.errors.full_messages.each do |message| %>

<%= message %>

          <% end %>

      <% end %>

        <%= f.label :username %>
        <%= f.text_field :username %>

        <%= f.label :password %>
        <%= f.text_field :password %>

        <% if params[:trainer] == "true" %>
          <%= f.label :user_type_id %>
          <%= f.text_field :user_type_id, :readonly => true, :value => '2' %>
        <% else %>
          <%= f.label :user_type_id %>
          <%= f.text_field :user_type_id, :readonly => true, :value => '1'  %>
        <% end %>

Account Profile

        <%= f.fields_for :profile do |profile| %>
          <%#= profile.inspect %>

              <%= profile.label :first_name %>
              <%= profile.text_field :first_name %>

              <%= profile.label :middle_name %>
              <%= profile.text_field :middle_name %>

              <%= profile.label :last_name %>
              <%= profile.text_field :last_name %>

              <%= profile.label :email %>
              <%= profile.text_field :email %>

              <%= profile.label :phone_number %>
              <%= profile.telephone_field :phone_number %>

              <%= profile.label :cell_phone %>
              <%= profile.telephone_field :cell_number %>

        <% end %>

        <%= f.submit %>

        <%= debug params %>
        <%= debug user %>
        <%= debug user.profile %>
    <% end %>


问:
How can we implement multiple custom action filters in web api?
How can we implement multiple custom action filters in web api?</p>
```<code>public class FileValidationAttribute : ActionFilterAttribute
{
    public override void OnActionExecuting(ActionExecutingContext context)
    {
        if (!context.ModelState.IsValid)
        {
            context.Result = new ValidationFailedResult(context.ModelState);
        }
    }
}

public class ModelStateFilterAttribute : ActionFilterAttribute
{
    public override void OnActionExecuting(ActionExecutingContext context)
    {
        if (!context.ModelState.IsValid)
        {
            throw new ApiException(context.ModelState);
        }
    }
}
</code>```

答:
To achieve this you need to register those attributes in the services (Dependency Injection).

Startup.cs

```<code>public void ConfigureServices(IServiceCollection services)
{
    .
    .
    services.AddScoped<FileValidationAttribute>();
    services.AddScoped<ModelStateFilterAttribute>();
    .
    .
}
</code>```

Use ServiceFilter attribute to call two filters in same action method.

Controller

```<code>[HttpGet("TestAction")]
[ServiceFilter(typeof(FileValidationAttribute))]
[ServiceFilter(typeof(ModelStateFilterAttribute))]
public async Task<IActionResult> TestAction()
{
    return StatusCode((int)HttpStatusCode.OK);
}
</code>```

Refer this link about ServiceFilter attribute

Body:
How can we implement multiple custom action filters in web api?

public class FileValidationAttribute : ActionFilterAttribute
{
    public override void OnActionExecuting(ActionExecutingContext context)
    {
        if (!context.ModelState.IsValid)
        {
            context.Result = new ValidationFailedResult(context.ModelState);
        }
    }
}

public class ModelStateFilterAttribute : ActionFilterAttribute
{
    public override void OnActionExecuting(ActionExecutingContext context)
    {
        if (!context.ModelState.IsValid)
        {
            throw new ApiException(context.ModelState);
        }
    }
}

Body:
To achieve this you need to register those attributes in the services (Dependency Injection).

Startup.cs

public void ConfigureServices(IServiceCollection services)
{
    .
    .
    services.AddScoped<FileValidationAttribute>();
    services.AddScoped<ModelStateFilterAttribute>();
    .
    .
}

Use ServiceFilter attribute to call two filters in same action method.

Controller

[HttpGet("TestAction")]
[ServiceFilter(typeof(FileValidationAttribute))]
[ServiceFilter(typeof(ModelStateFilterAttribute))]
public async Task<IActionResult> TestAction()
{
    return StatusCode((int)HttpStatusCode.OK);
}

Refer this link about ServiceFilter attribute


问:
ASP.NET Storing global variables - accessible from every page
I am building a large application and I ususally use a simple session to store private  global information however as the application could be rather large I belive this could be a problem due to the amount of memory sessions it could have.

Is there a better way to store such variables?

For example, when the user logs in I want to store data about that user and display it where needed without having to query the database each time.

答: If you think your data is too large for the Session, I would consider a database of some sort using cache so that you don't unnecessary calls.</p>

OwnerDisplayName: HenryH

LastEditorDisplayName: Rich B

ContentLicense: CC BY-SA 2.5


问:
Android Null Pointer Exception Madness?
So I have 3 Activities that need to all have access to the same custom class object (let's call it 'a') created by me when the very first Activity is created.

Because 'a' is made up of a whole bunch of non-primitives, I found it difficult to make Serializable or Parcelable. Instead I created a Service that binds to each Activity as they take the forefront, and gives the Activity 'a' in OnBind().

Now 'a' has a getter that gets another object of a different custom class stored with the same object (let's call it 'b'). In all three Activities, I also need to be able to access 'b'.

If I start the first Activity, use a button to navigate to the second Activity, press the "home" button on my phone, then go back into the application by pressing its icon, then navigate to the third activity by pressing a button, I get a null pointer exception on 'b' but not 'a'.

However if I add a line that prints 'a's getter for 'b' with sysout in the step where I press a button to get from the second Activity to the third, then there is no null pointer exception.

Does anybody know why this is and how I can resolve the issue?

答:
Sounds like you may want to consider a singleton class. An example (and description) in Java is here, but it boils down to:

```<code>public class ClassicSingleton {
    private static ClassicSingleton instance = null;
    protected ClassicSingleton() {
        // Exists only to defeat instantiation.
    }
    public static ClassicSingleton getInstance() {
        if(instance == null) {
            instance = new ClassicSingleton();
        }
        return instance;
    }
}
</code>```

Now, when you want to access the singleton object, just use:

```<code>ClassicSingleton instance = ClassicSingleton.getInstance();
</code>```

Sherif's solution would also work (and I was going to suggest this first, myself), but I prefer the singleton route as it's a little cleaner from an OO perspective.

Singletons have (at least) the following benefits over a global object:

Singletons use lazy instantiation so they are only created when they are first accessed, not when defined. If your object is costly to instantiate or maintain, it may be better to use a singleton rather than having it around for the life of the app

You can guarantee there will always be only one instance of a singleton - a global object can have as many instances as you have resources for

Title: Android Null Pointer Exception Madness?

Body:
Sounds like you may want to consider a singleton class. An example (and description) in Java is here, but it boils down to:

public class ClassicSingleton {
    private static ClassicSingleton instance = null;
    protected ClassicSingleton() {
        // Exists only to defeat instantiation.
    }
    public static ClassicSingleton getInstance() {
        if(instance == null) {
            instance = new ClassicSingleton();
        }
        return instance;
    }
}

Now, when you want to access the singleton object, just use:

ClassicSingleton instance = ClassicSingleton.getInstance();

Sherif's solution would also work (and I was going to suggest this first, myself), but I prefer the singleton route as it's a little cleaner from an OO perspective.

Singletons have (at least) the following benefits over a global object:

Singletons use lazy instantiation so they are only created when they are first accessed, not when defined. If your object is costly to instantiate or maintain, it may be better to use a singleton rather than having it around for the life of the app

You can guarantee there will always be only one instance of a singleton - a global object can have as many instances as you have resources for


问:
Jackson Deserialization: @JsonAlias doesn't work
I try to fill up an Java Object with a Json String, which can come with different kinds of variable names for the same field. That's why I try to use @JsonAlias. Unfortunately, I couldn't make it work yet for unknown reasons..

Here is my example:

The Java Object:

```<code>import com.fasterxml.jackson.annotation.JsonAlias;

public class ExampleClass {

    @JsonAlias({"test_1", "1"})
    private String test1;

    @JsonAlias({"test_2", "2"})
    private String test2;

    public String getTest1() {
        return test1;
    }

    public void setTest1(String test1) {
        this.test1 = test1;
    }

    public String getTest2() {
        return test2;
    }

    public void setTest2(String test2) {
        this.test2 = test2;
    }
}
</code>```

The Json, I try to deserialize:

```<code>ObjectMapper mapper = new ObjectMapper();

ExampleClass javaObject = mapper.readerFor(ExampleClass.class).readValue("{\"test_1\": \"heyo\", \"test_2\":  \"heyo2\" }");

</code>```

With "test_1" defined in the @JsonAlias Annotation above the field "test1", Jackson should find and fill up the field. But I get instead this following error:

```<code>17:02:34,653 ERROR [stderr] (default task-3) com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "test_1" (class ch.ejb.ExampleClass), not marked as ignorable (2 known properties: "test2", "test1"])

</code>```

edit: My Maven dependencies:

```<code>        <dependencies>

            <dependency>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.3.2</version>
            </dependency>
            <dependency><!-- add slf4j VYTH -->
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-simple</artifactId>
                <version>1.7.9</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.poi</groupId>
                <artifactId>poi</artifactId>
                <version>3.9</version>
            </dependency>
            <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-entitymanager</artifactId>
                <version>3.6.0.Final</version>

            </dependency>
            <dependency>
                <groupId>com.itextpdf</groupId>
                <artifactId>itextpdf</artifactId>
                <version>5.5.7</version>
            </dependency>
            <dependency>
                <groupId>org.freemarker</groupId>
                <artifactId>freemarker</artifactId>
                <version>2.3.23</version>
            </dependency>
            <dependency>
                <groupId>com.itextpdf.tool</groupId>
                <artifactId>xmlworker</artifactId>
                <version>5.5.7</version>
            </dependency>
            <dependency>
                <groupId>javax.ejb</groupId>
                <artifactId>javax.ejb-api</artifactId>
                <version>3.2.2</version>
            </dependency>
            <dependency>
                <groupId>javax.ws.rs</groupId>
                <artifactId>javax.ws.rs-api</artifactId>
                <version>2.0</version>
            </dependency>
            <dependency>
                <groupId>org.jboss.resteasy</groupId>
                <artifactId>resteasy-jaxrs</artifactId>
                <version>3.0.19.Final</version>
            </dependency>
            <dependency>
                <groupId>io.jsonwebtoken</groupId>
                <artifactId>jjwt</artifactId>
                <version>0.9.1</version>
                <exclusions>
                    <exclusion>
                        <groupId>com.fasterxml.jackson.core</groupId>
                        <artifactId>jackson-databind</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>

            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-text</artifactId>
                <version>1.9</version>
            </dependency>
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>javax.servlet-api</artifactId>
                <version>3.0.1</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>com.google.code.gson</groupId>
                <artifactId>gson</artifactId>
                <version>2.8.7</version>
            </dependency>
            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-databind</artifactId>
                <version>2.12.0</version>
            </dependency>
            <dependency>
                <groupId>io.swagger.core.v3</groupId>
                <artifactId>swagger-jaxrs2</artifactId>
                <scope>compile</scope>
                <version>2.0.10</version>
            </dependency>
            <dependency>
                <groupId>io.swagger.core.v3</groupId>
                <artifactId>swagger-annotations</artifactId>
                <version>2.0.10</version>
            </dependency>
            <dependency>
                <groupId>org.webjars</groupId>
                <artifactId>swagger-ui</artifactId>
                <version>2.1.4</version>
            </dependency>
            <dependency>
                <groupId>com.squareup.okhttp3</groupId>
                <artifactId>okhttp</artifactId>
                <version>4.9.1</version>
            </dependency>
            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-lang3</artifactId>
                <version>3.12.0</version>
            </dependency>
        </dependencies>
</code>```

The error code:

```<code>
13:36:10,858 ERROR [stderr] (default task-6) com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "test_1" (class ch.rest.opk.ExampleClass), not marked as ignorable (2 known properties: "test2", "test1"])
13:36:10,859 ERROR [stderr] (default task-6)  at [Source: {"test_1": "heyo", "test_2":  "heyo2" }; line: 1, column: 13] (through reference chain: ch.rest.opk.ExampleClass["test_1"])
13:36:10,860 ERROR [stderr] (default task-6)    at com.fasterxml.jackson.core.jackson-databind//com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:63)
13:36:10,861 ERROR [stderr] (default task-6)    at com.fasterxml.jackson.core.jackson-databind//com.fasterxml.jackson.databind.DeserializationContext.handleUnknownProperty(DeserializationContext.java:834)
13:36:10,862 ERROR [stderr] (default task-6)    at com.fasterxml.jackson.core.jackson-databind//com.fasterxml.jackson.databind.deser.std.StdDeserializer.handleUnknownProperty(StdDeserializer.java:1093)
13:36:10,863 ERROR [stderr] (default task-6)    at com.fasterxml.jackson.core.jackson-databind//com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownProperty(BeanDeserializerBase.java:1489)
13:36:10,864 ERROR [stderr] (default task-6)    at com.fasterxml.jackson.core.jackson-databind//com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownVanilla(BeanDeserializerBase.java:1467)
13:36:10,865 ERROR [stderr] (default task-6)    at com.fasterxml.jackson.core.jackson-databind//com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:282)
13:36:10,866 ERROR [stderr] (default task-6)    at com.fasterxml.jackson.core.jackson-databind//com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:140)
13:36:10,867 ERROR [stderr] (default task-6)    at com.fasterxml.jackson.core.jackson-databind//com.fasterxml.jackson.databind.ObjectReader._bindAndClose(ObjectReader.java:1626)
13:36:10,868 ERROR [stderr] (default task-6)    at com.fasterxml.jackson.core.jackson-databind//com.fasterxml.jackson.databind.ObjectReader.readValue(ObjectReader.java:1220)
13:36:10,869 ERROR [stderr] (default task-6)    at deployment.opk-backend.war//ch.rest.opk.LimitenServices.getLimitenExcel(LimitenServices.java:153)
13:36:10,870 ERROR [stderr] (default task-6)    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
13:36:10,870 ERROR [stderr] (default task-6)    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
13:36:10,871 ERROR [stderr] (default task-6)    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
13:36:10,872 ERROR [stderr] (default task-6)    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
13:36:10,873 ERROR [stderr] (default task-6)    at org.jboss.resteasy.resteasy-jaxrs//org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:140)
13:36:10,874 ERROR [stderr] (default task-6)    at org.jboss.resteasy.resteasy-jaxrs//org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:295)
13:36:10,875 ERROR [stderr] (default task-6)    at org.jboss.resteasy.resteasy-jaxrs//org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:249)
13:36:10,876 ERROR [stderr] (default task-6)    at org.jboss.resteasy.resteasy-jaxrs//org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:236)
13:36:10,877 ERROR [stderr] (default task-6)    at org.jboss.resteasy.resteasy-jaxrs//org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:406)
13:36:10,879 ERROR [stderr] (default task-6)    at org.jboss.resteasy.resteasy-jaxrs//org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:213)
13:36:10,880 ERROR [stderr] (default task-6)    at org.jboss.resteasy.resteasy-jaxrs//org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:228)
13:36:10,882 ERROR [stderr] (default task-6)    at org.jboss.resteasy.resteasy-jaxrs//org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)
13:36:10,883 ERROR [stderr] (default task-6)    at org.jboss.resteasy.resteasy-jaxrs//org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)
13:36:10,884 ERROR [stderr] (default task-6)    at javax.servlet.api//javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
13:36:10,885 ERROR [stderr] (default task-6)    at io.undertow.servlet//io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74)
13:36:10,886 ERROR [stderr] (default task-6)    at io.undertow.servlet//io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129)
13:36:10,887 ERROR [stderr] (default task-6)    at deployment.opk-backend.war//ch.rest.CorsResponseFilter.doFilter(CorsResponseFilter.java:56)
13:36:10,887 ERROR [stderr] (default task-6)    at io.undertow.servlet//io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
13:36:10,888 ERROR [stderr] (default task-6)    at io.undertow.servlet//io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
13:36:10,889 ERROR [stderr] (default task-6)    at io.undertow.servlet//io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)
13:36:10,890 ERROR [stderr] (default task-6)    at io.undertow.servlet//io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
13:36:10,891 ERROR [stderr] (default task-6)    at io.undertow.servlet//io.undertow.servlet.handlers.ServletChain$1.handleRequest(ServletChain.java:65)
13:36:10,892 ERROR [stderr] (default task-6)    at io.undertow.servlet//io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
13:36:10,893 ERROR [stderr] (default task-6)    at org.wildfly.extension.undertow//org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
13:36:10,894 ERROR [stderr] (default task-6)    at io.undertow.core//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
13:36:10,896 ERROR [stderr] (default task-6)    at io.undertow.servlet//io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
13:36:10,897 ERROR [stderr] (default task-6)    at io.undertow.servlet//io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
13:36:10,897 ERROR [stderr] (default task-6)    at io.undertow.core//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
13:36:10,898 ERROR [stderr] (default task-6)    at io.undertow.core//io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
13:36:10,899 ERROR [stderr] (default task-6)    at io.undertow.servlet//io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
13:36:10,900 ERROR [stderr] (default task-6)    at io.undertow.core//io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
13:36:10,901 ERROR [stderr] (default task-6)    at io.undertow.servlet//io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
13:36:10,902 ERROR [stderr] (default task-6)    at io.undertow.core//io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
13:36:10,903 ERROR [stderr] (default task-6)    at io.undertow.core//io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
13:36:10,905 ERROR [stderr] (default task-6)    at io.undertow.core//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
13:36:10,906 ERROR [stderr] (default task-6)    at org.wildfly.extension.undertow//org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
13:36:10,907 ERROR [stderr] (default task-6)    at io.undertow.core//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
13:36:10,908 ERROR [stderr] (default task-6)    at org.wildfly.extension.undertow//org.wildfly.extension.undertow.deployment.GlobalRequestControllerHandler.handleRequest(GlobalRequestControllerHandler.java:68)
13:36:10,909 ERROR [stderr] (default task-6)    at io.undertow.core//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
13:36:10,910 ERROR [stderr] (default task-6)    at io.undertow.servlet//io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292)
13:36:10,911 ERROR [stderr] (default task-6)    at io.undertow.servlet//io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81)
13:36:10,912 ERROR [stderr] (default task-6)    at io.undertow.servlet//io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138)
13:36:10,913 ERROR [stderr] (default task-6)    at io.undertow.servlet//io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)
13:36:10,914 ERROR [stderr] (default task-6)    at io.undertow.servlet//io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
13:36:10,915 ERROR [stderr] (default task-6)    at io.undertow.servlet//io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
13:36:10,916 ERROR [stderr] (default task-6)    at org.wildfly.extension.undertow//org.wildfly.extension.undertow.security.SecurityContextThreadSetupAction.lambda$create$0(SecurityContextThreadSetupAction.java:105)
13:36:10,917 ERROR [stderr] (default task-6)    at org.wildfly.extension.undertow//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1501)
13:36:10,918 ERROR [stderr] (default task-6)    at org.wildfly.extension.undertow//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1501)
13:36:10,919 ERROR [stderr] (default task-6)    at org.wildfly.extension.undertow//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1501)
13:36:10,920 ERROR [stderr] (default task-6)    at org.wildfly.extension.undertow//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1501)
13:36:10,921 ERROR [stderr] (default task-6)    at org.wildfly.extension.undertow//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1501)
13:36:10,922 ERROR [stderr] (default task-6)    at io.undertow.servlet//io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272)
13:36:10,924 ERROR [stderr] (default task-6)    at io.undertow.servlet//io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
13:36:10,925 ERROR [stderr] (default task-6)    at io.undertow.servlet//io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104)
13:36:10,926 ERROR [stderr] (default task-6)    at io.undertow.core//io.undertow.server.Connectors.executeRootHandler(Connectors.java:330)
13:36:10,926 ERROR [stderr] (default task-6)    at io.undertow.core//io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:812)
13:36:10,927 ERROR [stderr] (default task-6)    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
13:36:10,928 ERROR [stderr] (default task-6)    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
13:36:10,929 ERROR [stderr] (default task-6)    at java.base/java.lang.Thread.run(Thread.java:834)

</code>```

答:
I found the solution finally. The Problem was, that our JBoss Wildfly Server used Jackson Libraries as well and they caused an conflict. Probably because of the Version, which was something around 1.*

As soon as I excluded those old jackson libraries, @JsonAlias worked as expected:

```<code><jboss-deployment-structure>
<deployment>
    <exclusions>
        <module name="com.fasterxml.jackson.core.jackson-core" />
        <module name="com.fasterxml.jackson.core.jackson-databind" />
        <module name="com.fasterxml.jackson.jaxrs.jackson-jaxrs-json-provider" />
        <module name="org.jboss.resteasy.resteasy-jackson2-provider" />
    </exclusions>
</deployment>
</code>```

Body:
I try to fill up an Java Object with a Json String, which can come with different kinds of variable names for the same field. That's why I try to use @JsonAlias. Unfortunately, I couldn't make it work yet for unknown reasons..

Here is my example:

The Java Object:

import com.fasterxml.jackson.annotation.JsonAlias;

public class ExampleClass {

    @JsonAlias({"test_1", "1"})
    private String test1;

    @JsonAlias({"test_2", "2"})
    private String test2;

    public String getTest1() {
        return test1;
    }

    public void setTest1(String test1) {
        this.test1 = test1;
    }

    public String getTest2() {
        return test2;
    }

    public void setTest2(String test2) {
        this.test2 = test2;
    }
}

The Json, I try to deserialize:

ObjectMapper mapper = new ObjectMapper();

ExampleClass javaObject = mapper.readerFor(ExampleClass.class).readValue("{\"test_1\": \"heyo\", \"test_2\":  \"heyo2\" }");

With "test_1" defined in the @JsonAlias Annotation above the field "test1", Jackson should find and fill up the field. But I get instead this following error:

17:02:34,653 ERROR [stderr] (default task-3) com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "test_1" (class ch.ejb.ExampleClass), not marked as ignorable (2 known properties: "test2", "test1"])

edit: My Maven dependencies:

        <dependencies>

            <dependency>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.3.2</version>
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-simple</artifactId>
                <version>1.7.9</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.poi</groupId>
                <artifactId>poi</artifactId>
                <version>3.9</version>
            </dependency>
            <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-entitymanager</artifactId>
                <version>3.6.0.Final</version>

            </dependency>
            <dependency>
                <groupId>com.itextpdf</groupId>
                <artifactId>itextpdf</artifactId>
                <version>5.5.7</version>
            </dependency>
            <dependency>
                <groupId>org.freemarker</groupId>
                <artifactId>freemarker</artifactId>
                <version>2.3.23</version>
            </dependency>
            <dependency>
                <groupId>com.itextpdf.tool</groupId>
                <artifactId>xmlworker</artifactId>
                <version>5.5.7</version>
            </dependency>
            <dependency>
                <groupId>javax.ejb</groupId>
                <artifactId>javax.ejb-api</artifactId>
                <version>3.2.2</version>
            </dependency>
            <dependency>
                <groupId>javax.ws.rs</groupId>
                <artifactId>javax.ws.rs-api</artifactId>
                <version>2.0</version>
            </dependency>
            <dependency>
                <groupId>org.jboss.resteasy</groupId>
                <artifactId>resteasy-jaxrs</artifactId>
                <version>3.0.19.Final</version>
            </dependency>
            <dependency>
                <groupId>io.jsonwebtoken</groupId>
                <artifactId>jjwt</artifactId>
                <version>0.9.1</version>
                <exclusions>
                    <exclusion>
                        <groupId>com.fasterxml.jackson.core</groupId>
                        <artifactId>jackson-databind</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>

            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-text</artifactId>
                <version>1.9</version>
            </dependency>
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>javax.servlet-api</artifactId>
                <version>3.0.1</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>com.google.code.gson</groupId>
                <artifactId>gson</artifactId>
                <version>2.8.7</version>
            </dependency>
            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-databind</artifactId>
                <version>2.12.0</version>
            </dependency>
            <dependency>
                <groupId>io.swagger.core.v3</groupId>
                <artifactId>swagger-jaxrs2</artifactId>
                <scope>compile</scope>
                <version>2.0.10</version>
            </dependency>
            <dependency>
                <groupId>io.swagger.core.v3</groupId>
                <artifactId>swagger-annotations</artifactId>
                <version>2.0.10</version>
            </dependency>
            <dependency>
                <groupId>org.webjars</groupId>
                <artifactId>swagger-ui</artifactId>
                <version>2.1.4</version>
            </dependency>
            <dependency>
                <groupId>com.squareup.okhttp3</groupId>
                <artifactId>okhttp</artifactId>
                <version>4.9.1</version>
            </dependency>
            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-lang3</artifactId>
                <version>3.12.0</version>
            </dependency>
        </dependencies>

The error code:

13:36:10,858 ERROR [stderr] (default task-6) com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "test_1" (class ch.rest.opk.ExampleClass), not marked as ignorable (2 known properties: "test2", "test1"])
13:36:10,859 ERROR [stderr] (default task-6)  at [Source: {"test_1": "heyo", "test_2":  "heyo2" }; line: 1, column: 13] (through reference chain: ch.rest.opk.ExampleClass["test_1"])
13:36:10,860 ERROR [stderr] (default task-6)    at com.fasterxml.jackson.core.jackson-databind//com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:63)
13:36:10,861 ERROR [stderr] (default task-6)    at com.fasterxml.jackson.core.jackson-databind//com.fasterxml.jackson.databind.DeserializationContext.handleUnknownProperty(DeserializationContext.java:834)
13:36:10,862 ERROR [stderr] (default task-6)    at com.fasterxml.jackson.core.jackson-databind//com.fasterxml.jackson.databind.deser.std.StdDeserializer.handleUnknownProperty(StdDeserializer.java:1093)
13:36:10,863 ERROR [stderr] (default task-6)    at com.fasterxml.jackson.core.jackson-databind//com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownProperty(BeanDeserializerBase.java:1489)
13:36:10,864 ERROR [stderr] (default task-6)    at com.fasterxml.jackson.core.jackson-databind//com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownVanilla(BeanDeserializerBase.java:1467)
13:36:10,865 ERROR [stderr] (default task-6)    at com.fasterxml.jackson.core.jackson-databind//com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:282)
13:36:10,866 ERROR [stderr] (default task-6)    at com.fasterxml.jackson.core.jackson-databind//com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:140)
13:36:10,867 ERROR [stderr] (default task-6)    at com.fasterxml.jackson.core.jackson-databind//com.fasterxml.jackson.databind.ObjectReader._bindAndClose(ObjectReader.java:1626)
13:36:10,868 ERROR [stderr] (default task-6)    at com.fasterxml.jackson.core.jackson-databind//com.fasterxml.jackson.databind.ObjectReader.readValue(ObjectReader.java:1220)
13:36:10,869 ERROR [stderr] (default task-6)    at deployment.opk-backend.war//ch.rest.opk.LimitenServices.getLimitenExcel(LimitenServices.java:153)
13:36:10,870 ERROR [stderr] (default task-6)    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
13:36:10,870 ERROR [stderr] (default task-6)    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
13:36:10,871 ERROR [stderr] (default task-6)    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
13:36:10,872 ERROR [stderr] (default task-6)    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
13:36:10,873 ERROR [stderr] (default task-6)    at org.jboss.resteasy.resteasy-jaxrs//org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:140)
13:36:10,874 ERROR [stderr] (default task-6)    at org.jboss.resteasy.resteasy-jaxrs//org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:295)
13:36:10,875 ERROR [stderr] (default task-6)    at org.jboss.resteasy.resteasy-jaxrs//org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:249)
13:36:10,876 ERROR [stderr] (default task-6)    at org.jboss.resteasy.resteasy-jaxrs//org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:236)
13:36:10,877 ERROR [stderr] (default task-6)    at org.jboss.resteasy.resteasy-jaxrs//org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:406)
13:36:10,879 ERROR [stderr] (default task-6)    at org.jboss.resteasy.resteasy-jaxrs//org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:213)
13:36:10,880 ERROR [stderr] (default task-6)    at org.jboss.resteasy.resteasy-jaxrs//org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:228)
13:36:10,882 ERROR [stderr] (default task-6)    at org.jboss.resteasy.resteasy-jaxrs//org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)
13:36:10,883 ERROR [stderr] (default task-6)    at org.jboss.resteasy.resteasy-jaxrs//org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)
13:36:10,884 ERROR [stderr] (default task-6)    at javax.servlet.api//javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
13:36:10,885 ERROR [stderr] (default task-6)    at io.undertow.servlet//io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74)
13:36:10,886 ERROR [stderr] (default task-6)    at io.undertow.servlet//io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129)
13:36:10,887 ERROR [stderr] (default task-6)    at deployment.opk-backend.war//ch.rest.CorsResponseFilter.doFilter(CorsResponseFilter.java:56)
13:36:10,887 ERROR [stderr] (default task-6)    at io.undertow.servlet//io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
13:36:10,888 ERROR [stderr] (default task-6)    at io.undertow.servlet//io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
13:36:10,889 ERROR [stderr] (default task-6)    at io.undertow.servlet//io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)
13:36:10,890 ERROR [stderr] (default task-6)    at io.undertow.servlet//io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
13:36:10,891 ERROR [stderr] (default task-6)    at io.undertow.servlet//io.undertow.servlet.handlers.ServletChain$1.handleRequest(ServletChain.java:65)
13:36:10,892 ERROR [stderr] (default task-6)    at io.undertow.servlet//io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
13:36:10,893 ERROR [stderr] (default task-6)    at org.wildfly.extension.undertow//org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
13:36:10,894 ERROR [stderr] (default task-6)    at io.undertow.core//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
13:36:10,896 ERROR [stderr] (default task-6)    at io.undertow.servlet//io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
13:36:10,897 ERROR [stderr] (default task-6)    at io.undertow.servlet//io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
13:36:10,897 ERROR [stderr] (default task-6)    at io.undertow.core//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
13:36:10,898 ERROR [stderr] (default task-6)    at io.undertow.core//io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
13:36:10,899 ERROR [stderr] (default task-6)    at io.undertow.servlet//io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
13:36:10,900 ERROR [stderr] (default task-6)    at io.undertow.core//io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
13:36:10,901 ERROR [stderr] (default task-6)    at io.undertow.servlet//io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
13:36:10,902 ERROR [stderr] (default task-6)    at io.undertow.core//io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
13:36:10,903 ERROR [stderr] (default task-6)    at io.undertow.core//io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
13:36:10,905 ERROR [stderr] (default task-6)    at io.undertow.core//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
13:36:10,906 ERROR [stderr] (default task-6)    at org.wildfly.extension.undertow//org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
13:36:10,907 ERROR [stderr] (default task-6)    at io.undertow.core//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
13:36:10,908 ERROR [stderr] (default task-6)    at org.wildfly.extension.undertow//org.wildfly.extension.undertow.deployment.GlobalRequestControllerHandler.handleRequest(GlobalRequestControllerHandler.java:68)
13:36:10,909 ERROR [stderr] (default task-6)    at io.undertow.core//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
13:36:10,910 ERROR [stderr] (default task-6)    at io.undertow.servlet//io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292)
13:36:10,911 ERROR [stderr] (default task-6)    at io.undertow.servlet//io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81)
13:36:10,912 ERROR [stderr] (default task-6)    at io.undertow.servlet//io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138)
13:36:10,913 ERROR [stderr] (default task-6)    at io.undertow.servlet//io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)
13:36:10,914 ERROR [stderr] (default task-6)    at io.undertow.servlet//io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
13:36:10,915 ERROR [stderr] (default task-6)    at io.undertow.servlet//io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
13:36:10,916 ERROR [stderr] (default task-6)    at org.wildfly.extension.undertow//org.wildfly.extension.undertow.security.SecurityContextThreadSetupAction.lambda$create$0(SecurityContextThreadSetupAction.java:105)
13:36:10,917 ERROR [stderr] (default task-6)    at org.wildfly.extension.undertow//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1501)
13:36:10,918 ERROR [stderr] (default task-6)    at org.wildfly.extension.undertow//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1501)
13:36:10,919 ERROR [stderr] (default task-6)    at org.wildfly.extension.undertow//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1501)
13:36:10,920 ERROR [stderr] (default task-6)    at org.wildfly.extension.undertow//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1501)
13:36:10,921 ERROR [stderr] (default task-6)    at org.wildfly.extension.undertow//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1501)
13:36:10,922 ERROR [stderr] (default task-6)    at io.undertow.servlet//io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272)
13:36:10,924 ERROR [stderr] (default task-6)    at io.undertow.servlet//io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
13:36:10,925 ERROR [stderr] (default task-6)    at io.undertow.servlet//io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104)
13:36:10,926 ERROR [stderr] (default task-6)    at io.undertow.core//io.undertow.server.Connectors.executeRootHandler(Connectors.java:330)
13:36:10,926 ERROR [stderr] (default task-6)    at io.undertow.core//io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:812)
13:36:10,927 ERROR [stderr] (default task-6)    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
13:36:10,928 ERROR [stderr] (default task-6)    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
13:36:10,929 ERROR [stderr] (default task-6)    at java.base/java.lang.Thread.run(Thread.java:834)

Body:
I found the solution finally. The Problem was, that our JBoss Wildfly Server used Jackson Libraries as well and they caused an conflict. Probably because of the Version, which was something around 1.*

As soon as I excluded those old jackson libraries, @JsonAlias worked as expected:

<jboss-deployment-structure>
<deployment>
    <exclusions>
        <module name="com.fasterxml.jackson.core.jackson-core" />
        <module name="com.fasterxml.jackson.core.jackson-databind" />
        <module name="com.fasterxml.jackson.jaxrs.jackson-jaxrs-json-provider" />
        <module name="org.jboss.resteasy.resteasy-jackson2-provider" />
    </exclusions>
</deployment>


问:
C After filling buffers with data, strange data appear
Buy debugging through SWD on STM32F746NG and putting break point in last line of the code below:

```<code>uint16_t data[128];
q15_t ref[64];
q15_t in[64];
.
.
.
for(uint16_t ii=0;ii!=63;ii++)
  {
    ref[ii]=data[ii*2+1];
    in[ii]=data[ii*2+1];
  }

  // 3.LMS processing
    arm_lms_q15(
            &myLMS,
            in,
            ref,
            dummyOut,
            error,
            nsamples
            );

  // 4.Visualizing errors
for(uint16_t bytecount=0;bytecount!=64;bytecount++)
</code>```

Obviously all elemnt of ref and in must be the same but the last elemnt of these are not the same. the last element of data is 2617 bu is -15581 on ref and 2409 on in.
The question is how to remove this data corruption in last element?

答:
Always write loops as simple as possible. for(uint16_t ii=0;ii!=63;ii++) has a weird name ii for no reason. i stands for iterator, what does ii stand for? Also it checks != 63 for no reason.

An idiomatic for loop is written as for(uint16_t i=0; i<n; i++) and deviating from that form is often "code smell".

You should have

```<code>#define REF_MAX 64  // replace this with some meaningful name.
...

// remove magic numbers:
uint16_t data[REF_MAX*2];
q15_t ref [REF_MAX];
q15_t in  [REF_MAX];

// idiomatic for loop without magic numbers:
for(uint16_t i=0; i<REF_MAX; i++)
{
  ref[i] = data[i*2+1];
  in[i]  = data[i*2+1];
}
</code>```

Now the highest index access of ref and in will be 63 (the 64th item) and the highest index acess of data will be 63*2 + 1 = 127 (the 128th item).

Unrelated to your issue, it's not a good idea to allocate large arrays like this on the stack when coding for microcontroller embedded systems. You then get a stack peak use of >256 bytes when this function is called, which is very dangerous. Declare these buffers as static so they end up in .bss instead of the stack.

Body:
Buy debugging through SWD on STM32F746NG and putting break point in last line of the code below:

uint16_t data[128];
q15_t ref[64];
q15_t in[64];
.
.
.
for(uint16_t ii=0;ii!=63;ii++)
  {
    ref[ii]=data[ii*2+1];
    in[ii]=data[ii*2+1];
  }

  // 3.LMS processing
    arm_lms_q15(
            &myLMS,
            in,
            ref,
            dummyOut,
            error,
            nsamples
            );

  // 4.Visualizing errors
for(uint16_t bytecount=0;bytecount!=64;bytecount++)

Obviously all elemnt of ref and in must be the same but the last elemnt of these are not the same. the last element of data is 2617 bu is -15581 on ref and 2409 on in.
The question is how to remove this data corruption in last element?

Body:
Always write loops as simple as possible. for(uint16_t ii=0;ii!=63;ii++) has a weird name ii for no reason. i stands for iterator, what does ii stand for? Also it checks != 63 for no reason.

An idiomatic for loop is written as for(uint16_t i=0; i<n; i++) and deviating from that form is often "code smell".

You should have

#define REF_MAX 64  // replace this with some meaningful name.
...

// remove magic numbers:
uint16_t data[REF_MAX*2];
q15_t ref [REF_MAX];
q15_t in  [REF_MAX];

// idiomatic for loop without magic numbers:
for(uint16_t i=0; i<REF_MAX; i++)
{
  ref[i] = data[i*2+1];
  in[i]  = data[i*2+1];
}

Now the highest index access of ref and in will be 63 (the 64th item) and the highest index acess of data will be 63*2 + 1 = 127 (the 128th item).

Unrelated to your issue, it's not a good idea to allocate large arrays like this on the stack when coding for microcontroller embedded systems. You then get a stack peak use of >256 bytes when this function is called, which is very dangerous. Declare these buffers as static so they end up in .bss instead of the stack.


问:
SqlModel datetime field is throwing error upon execution
I am using SQLModel in python 3.8

When I add my datetime field created_at: datetime = Field(default_factory=utcnow(), nullable=False)

I get this
Error

```<code>File "./app/main.py", line 16, in <module>
    class Post(SQLModel, table=True):
  File "/Users/markwardell/PycharmProjects/pythonProject/venv/lib/python3.8/site-packages/sqlmodel/main.py", line 277, in __new__
    new_cls = super().__new__(cls, name, bases, dict_used, **config_kwargs)
  File "pydantic/main.py", line 204, in pydantic.main.ModelMetaclass.__new__
  File "pydantic/fields.py", line 488, in pydantic.fields.ModelField.infer
  File "pydantic/fields.py", line 419, in pydantic.fields.ModelField.__init__
  File "pydantic/fields.py", line 539, in pydantic.fields.ModelField.prepare
  File "pydantic/fields.py", line 801, in pydantic.fields.ModelField.populate_validators
  File "pydantic/validators.py", line 718, in find_validators
RuntimeError: error checking inheritance of <module 'datetime' from '/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/datetime.py'> (type: module)
</code>```

If I do not the add the created_at the table is created in PostgresSql as expected.
Code

```<code>import datetime
from typing import Optional
import utcnow as utcnow
from fastapi import FastAPI
from sqlalchemy import TIMESTAMP, text
from sqlmodel import Field, Session, SQLModel, create_engine, select
from app.database import SQLALCHEMY_DATABASE_URL

class Hero(SQLModel, table=True):
    id: Optional[int] = Field(default=None, primary_key=True)
    name: str = Field(index=True)
    secret_name: str
    age: Optional[int] = Field(default=None, index=True)

class Post(SQLModel, table=True):
    id: Optional[int] = Field(default=None, primary_key=True, nullable=False)
    title: str = Field(nullable=False)
    content: str = Field(nullable=False)
    published: bool = Field(default=True, nullable=False)
    created_at: datetime = Field(default_factory=utcnow(), nullable=False)

engine = create_engine(SQLALCHEMY_DATABASE_URL)

def create_db_and_tables():
    SQLModel.metadata.create_all(engine)

app = FastAPI()

@app.on_event("startup")
def on_startup():
    create_db_and_tables()
</code>```

答:
This was explained in a comment, but just to add it as an answer for others:

You must import datetime like this

from datetime import datetime
```

The datetime we require in this context is a actually a class inside a module that is also called datetime.

Body:
I am using SQLModel in python 3.8

When I add my datetime field created_at: datetime = Field(default_factory=utcnow(), nullable=False)

I get this
Error

File "./app/main.py", line 16, in <module>
    class Post(SQLModel, table=True):
  File "/Users/markwardell/PycharmProjects/pythonProject/venv/lib/python3.8/site-packages/sqlmodel/main.py", line 277, in __new__
    new_cls = super().__new__(cls, name, bases, dict_used, **config_kwargs)
  File "pydantic/main.py", line 204, in pydantic.main.ModelMetaclass.__new__
  File "pydantic/fields.py", line 488, in pydantic.fields.ModelField.infer
  File "pydantic/fields.py", line 419, in pydantic.fields.ModelField.__init__
  File "pydantic/fields.py", line 539, in pydantic.fields.ModelField.prepare
  File "pydantic/fields.py", line 801, in pydantic.fields.ModelField.populate_validators
  File "pydantic/validators.py", line 718, in find_validators
RuntimeError: error checking inheritance of <module 'datetime' from '/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/datetime.py'> (type: module)

If I do not the add the created_at the table is created in PostgresSql as expected.
Code

import datetime
from typing import Optional
import utcnow as utcnow
from fastapi import FastAPI
from sqlalchemy import TIMESTAMP, text
from sqlmodel import Field, Session, SQLModel, create_engine, select
from app.database import SQLALCHEMY_DATABASE_URL

class Hero(SQLModel, table=True):
    id: Optional[int] = Field(default=None, primary_key=True)
    name: str = Field(index=True)
    secret_name: str
    age: Optional[int] = Field(default=None, index=True)

class Post(SQLModel, table=True):
    id: Optional[int] = Field(default=None, primary_key=True, nullable=False)
    title: str = Field(nullable=False)
    content: str = Field(nullable=False)
    published: bool = Field(default=True, nullable=False)
    created_at: datetime = Field(default_factory=utcnow(), nullable=False)

engine = create_engine(SQLALCHEMY_DATABASE_URL)

def create_db_and_tables():
    SQLModel.metadata.create_all(engine)

app = FastAPI()

@app.on_event("startup")
def on_startup():
    create_db_and_tables()

Body:
This was explained in a comment, but just to add it as an answer for others:

You must import datetime like this

from datetime import datetime

The datetime we require in this context is a actually a class inside a module that is also called datetime.


问:
Cannot disable "white-space: nowrap;" on html div
On my website app, I have a logger window. In that window, I have table rows with divs inside.

I was able to crop long sentences for users. What I want is, when one hovers an item, it will show all sentences of that item.

It actually works for the last item. But why it does not work for the first item?

.TGC_LibBootGUIDebug {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.TGC_LibBootGUIDebug:hover {
  overflow: visible;
  white-space: normal;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><table>
  <tbody>
    <tr>
      <td>
        <div class="TGC_LibBootGUIDebug">- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce vel commodo justo. Aenean vitae tellus vitae libero scelerisque tincidunt eu facilisis tellus. In tincidunt in mi in semper. Vivamus fermentum massa sagittis ullamcorper pulvinar. Ut id volutpat lectus. Nulla eget vulputate orci, id efficitur mauris. Donec lacinia consequat tortor vitae finibus. Phasellus a sem quis arcu iaculis finibus. Quisque tristique, purus ac sollicitudin efficitur, quam libero luctus massa, eget congue urna tellus ut dui.
        </div>
      </td>
    </tr>
    <tr>
      <td>
        <div class="TGC_LibBootGUIDebug">- Ut accumsan mattis eros ac hendrerit. Interdum et malesuada fames ac ante ipsum primis in faucibus. Aenean condimentum massa et vestibulum vestibulum. Aenean ac imperdiet arcu. Duis quis elit nibh. Nam tortor nunc, tristique eget dolor eu, placerat accumsan ligula. Mauris at odio cursus, scelerisque lectus nec, interdum erat. Sed facilisis ex vitae magna mattis dictum. Praesent molestie eros id diam sagittis pharetra. Donec sit amet tellus sem. Nullam iaculis nulla sit amet tellus bibendum, vel congue leo commodo. Cras accumsan imperdiet lorem, quis dictum arcu interdum a. In sollicitudin lacinia libero, sit amet accumsan enim mattis vitae.
        </div>
      </td>
    </tr>
  </tbody>
</table></code>```

答:
The div does not have a width set, and white-space: nowrap is set, which causes the cell to be automatically stretched by the content. Just set a width for the div.</p>
```<code>.TGC_LibBootGUIDebug {
    width: 400px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
</code>```

Body:
On my website app, I have a logger window. In that window, I have table rows with divs inside.

I was able to crop long sentences for users. What I want is, when one hovers an item, it will show all sentences of that item.

It actually works for the last item. But why it does not work for the first item?

.TGC_LibBootGUIDebug {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.TGC_LibBootGUIDebug:hover {
  overflow: visible;
  white-space: normal;
}

- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce vel commodo justo. Aenean vitae tellus vitae libero scelerisque tincidunt eu facilisis tellus. In tincidunt in mi in semper. Vivamus fermentum massa sagittis ullamcorper pulvinar. Ut id volutpat lectus. Nulla eget vulputate orci, id efficitur mauris. Donec lacinia consequat tortor vitae finibus. Phasellus a sem quis arcu iaculis finibus. Quisque tristique, purus ac sollicitudin efficitur, quam libero luctus massa, eget congue urna tellus ut dui.

- Ut accumsan mattis eros ac hendrerit. Interdum et malesuada fames ac ante ipsum primis in faucibus. Aenean condimentum massa et vestibulum vestibulum. Aenean ac imperdiet arcu. Duis quis elit nibh. Nam tortor nunc, tristique eget dolor eu, placerat accumsan ligula. Mauris at odio cursus, scelerisque lectus nec, interdum erat. Sed facilisis ex vitae magna mattis dictum. Praesent molestie eros id diam sagittis pharetra. Donec sit amet tellus sem. Nullam iaculis nulla sit amet tellus bibendum, vel congue leo commodo. Cras accumsan imperdiet lorem, quis dictum arcu interdum a. In sollicitudin lacinia libero, sit amet accumsan enim mattis vitae.

Body:
The div does not have a width set, and white-space: nowrap is set, which causes the cell to be automatically stretched by the content. Just set a width for the div.

.TGC_LibBootGUIDebug {
    width: 400px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}


问:
ERC721: This contract may be abstract not implement an abstract parents methods completely or not invoke an inherited contract's constructor correctly
I got the codes below from this link: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
but its not working ?

```<code>pragma solidity ^0.4.20;
interface ERC721 /* is ERC165 */ {
    event Transfer(address indexed _from, address indexed _to, uint256 indexed _tokenId);
    event Approval(address indexed _owner, address indexed _approved, uint256 indexed _tokenId);
    event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);
    function balanceOf(address _owner) external view returns (uint256);
    function ownerOf(uint256 _tokenId) external view returns (address);
    function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data) external payable;
    function safeTransferFrom(address _from, address _to, uint256 _tokenId) external payable;
    function transferFrom(address _from, address _to, uint256 _tokenId) external payable;
    function approve(address _approved, uint256 _tokenId) external payable;
    function setApprovalForAll(address _operator, bool _approved) external;
    function getApproved(uint256 _tokenId) external view returns (address);
    function isApprovedForAll(address _owner, address _operator) external view returns (bool);
}

interface ERC165 {
    function supportsInterface(bytes4 interfaceID) external view returns (bool);
}
</code>```

答:
Since you're trying to deploy an interface of ERC721.
If you would like to deploy an ERC721 contract, then you should have the contract code as below:

```<code>contract MyERC721 is ERC721 {
   // your constructor and code here
   ...
}
</code>```

and your MyERC721 contract will succeed the ERC721 interface function.

Body:
I got the codes below from this link: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
but its not working ?

pragma solidity ^0.4.20;
interface ERC721 /* is ERC165 */ {
    event Transfer(address indexed _from, address indexed _to, uint256 indexed _tokenId);
    event Approval(address indexed _owner, address indexed _approved, uint256 indexed _tokenId);
    event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);
    function balanceOf(address _owner) external view returns (uint256);
    function ownerOf(uint256 _tokenId) external view returns (address);
    function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data) external payable;
    function safeTransferFrom(address _from, address _to, uint256 _tokenId) external payable;
    function transferFrom(address _from, address _to, uint256 _tokenId) external payable;
    function approve(address _approved, uint256 _tokenId) external payable;
    function setApprovalForAll(address _operator, bool _approved) external;
    function getApproved(uint256 _tokenId) external view returns (address);
    function isApprovedForAll(address _owner, address _operator) external view returns (bool);
}

interface ERC165 {
    function supportsInterface(bytes4 interfaceID) external view returns (bool);
}

Body:
Since you're trying to deploy an interface of ERC721.
If you would like to deploy an ERC721 contract, then you should have the contract code as below:

contract MyERC721 is ERC721 {
   // your constructor and code here
   ...
}

and your MyERC721 contract will succeed the ERC721 interface function.


问:
How to do YARN role graceful shutdown on a Cloudera Manager datanode CDH 6.3.2
Can not find answer on this question.

How to gracefully stop YARN role on a data node and wait till all running jobs on a datanode will finish with status success.

I know that in ClouderaManager you can decommission yarn role when you can stop it.
If I do YARN role decommission
The running jobs will fail with exit code killed or crash status.

Is this a safe way to YARN role stop on a data node?

Is this a graceful yarn role shutdown or where is other way to do this?
all jobs have killed status after YARN role decommission

答:
YARN Graceful decommission will wait for jobs to complete. You can pass the timeout value so that YARN will start decommission after x seconds. If no jobs running within x secs then automatically YARN will start decommission without waiting for timeout to happen.

CM -> Clusters -> yarn -> Configuration -> In search bar (

yarn.resourcemanager.nodemanager-graceful-decommission-timeout-secs)
Set the value and save the configuration and do restart to deploy configs.
To decommission a specific host/more hosts

CM -> Clusters -> yarn -> Instances (Select the hosts that you want to decommission)

Click -> Actions for selected hosts -> Decommission
In case you want to decommission all the roles of a host then follow this doc
https://docs.cloudera.com/documentation/enterprise/6/6.3/topics/cm_mc_host_maint.html#decomm_host